Phpexcel Reading problem

Topics: Developer Forum, User Forum
Jul 17, 2012 at 8:03 PM

I need to convert xls or xlsx file to csv.

this xls/xlsx file given by different supplier in different format. I need to retrieve the data in a column which contains date. Some supplier format this column as "date"... some supplier leave date column format as "general". Date format is also different.Like could be 01/01/2012

1 january 2012, 01, jan 12 

So i am developing an interface for another team who will use this software to convert excel to csv. Same supplier always same format of data. So I am using a table to store suppliers excel data format. 

I have to retrieve 3 more columns which content is place, rate etc.


Now, I am reading all the cells using getFormattedValue()

But whenever I use this command it will format cell which is not even similar as excel cell.

in the excel cell got value like 12-12-2012

but phpexcel give me value 12-12-12 some times it give me just a number

I need date in 12/12/2012 format. Input could be any format(defined by the user

$date_format='d-m-Y';// it come from database
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

$filterSubset = new MyReadFilter($begin,$finish,range($lowest_col,$heighest_col)); 
echo 'Loading Sheet using filter'; 
$objPHPExcel = new PHPExcel();

$objPHPExcel = $objReader->load($target_path);

$dail_code= array();
$destination= array();

	     $objWorksheet = $objPHPExcel->setActiveSheetIndex(0); 
		   $f=$objWorksheet->getCell( $rate_col.$start3)->getFormattedValue();  
$date = DateTime::createFromFormat($date_format,$p);
This code is not working properly because in excel cell value was like 12-12-2012
phpexcel make it as 12-12-12;
and createFormFormat('d-m-Y',12-12-12) can not work...because format is i need whatever inside the cell should read properly...
Is there any one who can help me????






Jul 17, 2012 at 9:37 PM

If the date value in the cell is an actual Excel date value (rather than a string), then use PHP's built in date handling functions to convert it directly to a PHP date/time value or DateTime object. If it's a string, then you don't need to use getFormattedValue(), simply use getValue() to read the raw string.