End column of excel file

Jul 4, 2011 at 10:58 AM
Edited Jul 4, 2011 at 10:59 AM

When we convert excel file to CSV file by first reading an Excel file and then writing a CSV file, we end up with lot of unwanted data as all the unused columns are read and written into CSV file with the delimiter. But the number of rows are automatically sensed and duplicated onto CSV.

 

So my query is how do I limit the nos. of column to be rewritten into a CSV file. The code is here:

 

 

/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';

$wbname = 'myexcel.xlsx'; 
if (!file_exists("$wbname")) { 
	$log->logit('Error',"Excel workbook $wbname missing!"); 
	return FALSE; 
} 

echo date('H:i:s') . " Load from Excel2007 file"."<br>";
$objPHPExcel = PHPExcel_IOFactory::load($wbname);
$objPHPExcel->setActiveSheetIndex(0);

echo date('H:i:s') . " Write to CSV format"."<br>";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')
    ->setDelimiter(',')
    ->setEnclosure('\'')
    ->setSheetIndex(0)
    ->save(str_replace('.php', '.csv', __FILE__));
?>
Jul 5, 2011 at 7:37 AM

I think setReadDataOnly(true), solves the problem. Thanks. And compliments for a great product.