以下是我的脚本,我在其中放置进度条来告诉用户正在处理的工作表数据的进度问题是进度条出现在将 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>';