nuovo / spreadsheet-reader

A PHP spreadsheet reader (Excel XLS and XLSX, OpenOffice ODS, and variously separated text files) with a singular goal of getting the data out, efficiently
http://www.nuovo.lv/
Other
674 stars 498 forks source link

Issue with dates format (YYYY-MM-DD) #113

Open borjakhet opened 8 years ago

borjakhet commented 8 years ago

Using this code:

require_once(dirname(__FILE__) . '/../ext/spreadsheet-reader/SpreadsheetReader.php');
require_once(dirname(__FILE__) . '/../ext/spreadsheet-reader/php-excel-reader/excel_reader2.php');

$pCsvPath =  Config::$generatedCSVPath . "/" . str_replace(array(".xlsx", ".xls"), ".csv", $pFileName);

$csv = fopen($pCsvPath, "w");

$pReader = new SpreadsheetReader($pFilePath);

// Read only the first sheet
$pSheets = $pReader -> Sheets();
$pReader -> ChangeSheet(0);

foreach ($pReader as $row)
{
    fputcsv($csv, $row);
}

Everything's ok, but I'm having problems with the dates.

There's a column on the .xls / .xlsx files with the following format 2015-02-10 When I write them to .csv, the output of this column is 2015201520152015-FebFeb-TueTue.

How can I convert it to .csv using the code I post above but maintaining the date as the correct format (2015-02-10)?

If I manually change the dates from 2015-01-01 to 01-01-2015 (put the year at the end) the dates are parsed correctly

Thanks in advance.

k4rz4 commented 8 years ago

I have encountered the same problem, did you found solution? Thanks in advance!

Nishi1 commented 7 years ago

We can separate year, month and day with back slash (/) in uploaded xls file like YYYY/MM/DD. Then $date = date('Y-m-d',strtotime(str_replace('/','-',$data->sheets[$i]['cells'][$j][5])));

manisapr commented 5 years ago

hello i have also facing same problem how to solve this