Hello Iwol,
Thank you for helping me and the patient with me. I have it working now BUT what is left now that I have a problem with the field with a time mask.
Look, the way it goes is that there are different Excel file's which are used by members of different committee's. These members understand Excel. I'm the webmaster but I don't want to fill in all these data, which is already maintained by the different commitee's, in a database. But in these Excel file's there is all different kinds of data like text, date (01-03-2011), time (09:30:00). But maybe was this already clear.
Here is my code which is working for a fields with a date mask (if statement) and text/general mask (else) statement. If a field with a time mask is done in the else part then it is correct written into the database! But now the field with a time mask is running into the if part, whch is returning a date like 1970-01-01 or 2012-03-11.
So how can I distinguish a field with a date mask and a field with a time mask? The method isDateTime is not enough?
if (!is_null($cell)) {//The isDateTime function/method is only working for a field with a date mask! If the cell does have a time mask then//the isDateTime method recognize this as a DateTime field and the code is running into the if statement and returning//DATE--> which is wrong when the value is 09:30:00if (PHPExcel_Shared_Date::isDateTime($cell)) {//This prints the date according to the date in Excel. So far so good.//echo '
$data: '.PHPExcel_Style_NumberFormat::toFormattedString($cell->getValue(), "M/D/YYYY").' --/-- '.PHPExcel_Style_NumberFormat::toFormattedString($cell->getValue(), "YYYY-M-D").'
'; $data = PHPExcel_Style_NumberFormat::toFormattedString(iconv("UTF-8", "ISO-8859-1", $cell->getFormattedValue()), "yyyy-mm-dd"); $imp_data[$ic] = date("Y-m-d",strtotime($data));//Why doesn't next lines not working? I should like that this construction works because then I'm using the formatting of PHPExcel//$data = $cell->getFormattedValue()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2).'
';//$data = $cell->getCalculatedValue()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2).'
';//$data = $cell->getValue()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2).'
';//$data = $cell->getValue()->setFormatCode(PHPExcel_Style_NumberFormat::toFormattedString($cell->getValue(), "yyyy-mm-dd"));//$data = PHPExcel_Style_NumberFormat::toFormattedString($cell->getValue(), "yyyy-mm-dd");//$data = $cell->getValue()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);//echo '$data: '.$ic.' --/--'.$data.'
'; } else {//echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , PHP_EOL;//echo '', $worksheet->getCell('G2')->getCalculatedValue(), '' , PHP_EOL; $imp_data[$ic] = iconv("UTF-8", "ISO-8859-1", $cell->getFormattedValue()); }echo'', $imp_data[$ic], '' , PHP_EOL; $ic = $ic + 1; } else {echo'field is empty or not a date'; }
Thanks in advance,
Nico