使用PHPEXCEL lib将XLS转换为CSV,但不将空行传输到CSV文件中

时间:2017-05-28 09:51:43

标签: php excel csv phpexcel xls

以下代码将XLS文件的每个工作表转换为CSV文件。但我找不到办法阻止它将XLS中的空白行包含在CSV中。

请帮帮我。

   function convertXLStoCSV($infile, $outfile) // the function that converts the file
{
    $fileType = PHPExcel_IOFactory::identify($infile);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($infile);

    $writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $writer->setDelimiter(",");
    $writer->setEnclosure("");
    foreach ($objPHPExcel->getWorksheetIterator() as $workSheetIndex => $worksheet) 
    {
        $objPHPExcel->setActiveSheetIndex($workSheetIndex);
        $writer->setSheetIndex($workSheetIndex);
        $writer->save('converted/' . $outfile ."_" . $worksheet->getTitle() . ".csv");


        echo $outfile;
        echo $infile;
    }
}

0 个答案:

没有答案