0

以下是我将 xls 转换为 csv 的脚本。无论在for循环的代码之前提到什么,我都面临的问题,它首先运行。请让我知道如何首先从以下脚本显示图像,然后运行循环脚本:

<body>

asdjasldjasdlj // Even this text gets load after execution of for loop
<!-- Progress information -->
<div id="information" style="width"><img src="images/L.gif" /></div>

<?php 
     require_once 'lib/excel_reader2.php';
    $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;

for($i = 0; $i < $nbSheets; $i++) {
           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>';

?>
</body>
4

1 回答 1

3

您可以使用 flush() 函数

它将当前输出一直推送到浏览器。

http://php.net/manual/en/function.flush.php

于 2012-12-09T10:09:10.020 回答