即時通訊使用這幾行轉換一個xlsx,其中包含4sheets轉換爲.csv。但它只轉換xlsx文件的第一張。我怎麼能使它轉換每一張xlsx。繼承人的代碼,PHPExcel將多個xlsx轉換爲csv
error_reporting(E_ALL);
date_default_timezone_set($this->vendor_timezone);
/** PHPExcel_IOFactory */
require_once sfConfig::get('sf_root_dir').'/lib/PHPExcel/IOFactory.php';
$file=sfConfig::get("sf_upload_dir").DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR."1344500254_MyExcel.xlsx";
// Check prerequisites
//print sfConfig::get("sf_upload_dir").DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR; exit;
if (!file_exists($file)) {
exit($file."Please run 06largescale.php first.\n");
}
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($file);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save(str_replace('.xlsx', '.csv',$file));
return "success";
哦,那就是爲什麼。太糟糕了。在使用
轉換之前,我已經指定了該工作表。非常感謝! – 2012-08-13 04:00:51只是要清楚,沒有辦法寫入單個CSV,但如果您查看我的答案,則可以輕鬆地將每個工作表寫入不同的CSV文件。 – 2015-06-18 01:28:05