以下は、.xls ファイルを読み取って .csv に変換する私の php コードです。スクリプトは完全に正常に機能していますが、私が直面している問題は、デフォルトで 1 つのシートでしか機能しないことです。私がやろうとしているのは、.xls ファイルにあるすべてのシートからデータを読み取り、出力を data.csv に保存するように、次のスクリプトを変更する必要があるということです。どうすればそれができるか教えてください。
ありがとう、
私は次のライブラリを使用しています:
http://sourceforge.net/projects/phpexcelreader/
require_once 'lib/reader.php';
$excel = new Spreadsheet_Excel_Reader();
$excel->setOutputEncoding('CP1251');
$excel->read('Student.xls');
$x=1;
$sep = ",";
ob_start();
while($x<=$excel->sheets[0]['numRows']) {
$y=1;
$row="";
while($y<=$excel->sheets[0]['numCols']) {
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
$row.=($row=="")?"\"".$cell."\"":"".$sep."\"".$cell."\"";
$y++;
}
echo $row."\n";
$x++;
}
$fp = fopen("data.csv",'a');
fwrite($fp,ob_get_contents());
fclose($fp);
ob_end_clean();
echo "CSV file created successfully";