.xls to .csv keeping the empty cells

Topics: Developer Forum, Project Management Forum, User Forum
Mar 29, 2012 at 2:58 PM
Edited Mar 29, 2012 at 3:18 PM

How can I convert a .xls to .csv keeping the empty cells?

I use this code, but the file was created without the empty cells.

 

function xls_to_csv_files($xlsfile,$delimiter=NULL,$useBOM=true)
{   
    if (!file_exists($xlsfile))
        return false;
   
    include('PHPExcel.php');
    include('PHPExcel/IOFactory.php');
   
    $base = basename($xlsfile,".xls");
    if( is_null($delimiter) ) $delimiter = chr(9);
   
    $objReader = PHPExcel_IOFactory::createReader('Excel5');
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($xlsfile);

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $objWriter->setDelimiter($delimiter);
    $objWriter->setEnclosure('');
    $objWriter->setLineEnding("\r\n");
    $objWriter->setSheetIndex(0);
    $objWriter->setUseBOM(true);
    $objWriter->save('upload/stock_blanes.csv');
}

xls_to_csv_files('upload/stock_blanes.xls');

Mar 29, 2012 at 4:23 PM

Resolved!

Mar 5, 2013 at 12:54 PM
Hi,

And can we know the solution please ?

Thx