【发布时间】:2012-12-09 08:20:22
【问题描述】:
以下是我的脚本,我在其中放置进度条来告诉用户正在处理的工作表数据的进度问题是进度条出现在将 xls 保存到 csv 的整个过程完成后请告诉我如何我可以修改以下内容,以便在当前工作表正在处理时正确显示进度条。谢谢,
$excel = new Spreadsheet_Excel_Reader();
$excel->setOutputEncoding('UTF-16');
$excel->read('Student2.xls');
$x=1;
$sep = ",";
$nbSheets = count($excel->sheets);
echo $x." - ".$nbSheets;
$total = $nbSheets - 1;
for($i = 0; $i < $nbSheets; $i++) {
// Calculate the percentation
$percent = intval($i/$total * 100)."%";
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
//sleep(1);
ob_start();
while($x<=$excel->sheets[$i]['numRows']) {
$y=1;
$row="";
while($y<=$excel->sheets[$i]['numCols']) {
$cell = isset($excel->sheets[$i]['cells'][$x][$y]) ? $excel->sheets[$i]['cells'][$x][$y] : '';
$row.=($row=="")?"\"".$cell."\"":"".$sep."\"".$cell."\"";
$y++;
}
echo $row."\n";
$x++;
}
$x = 1; $y = 1;
$fp = fopen("data.csv",'a');
fwrite($fp,ob_get_contents());
fclose($fp);
ob_end_clean();
}
echo "CSV file created successfully";
// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
【问题讨论】:
-
您必须为此使用 AJAX。
-
@YogeshSuthar 请看一下stuff.w3shaman.com/php-progress-bar 这是工作示例。
-
请不要使用
language="javascript"。这是无效的。 -
上面的链接我提到它包含与上面相同的for循环,唯一的区别是上面的代码包含转储数据的脚本而我提到的链接没有。
标签: php javascript