Using PHPExcel, we are converting from xlsx to csv file.
When converting date type data, the converted value will change depending on the date delimiter.
I want to unify the output format of the converted date format to'yyyy-mm-dd'.
- xlsx → csv conversion process
$reader = PHPExcel_IOFactory :: createReader ('Excel2007'); $book = $reader->load ("./hoge.xlsx");// xlsx file path to csv $writer = PHPExcel_IOFactory :: createWriter ($book,'CSV')->setDelimiter (',')); $writer->save ("./hoge.csv");
- xlsx sample and csv converted value
date 2020-12-31 // (Hyphen delimited) → 2020-12-31 2020/12/31 // (slash delimited) → 12-31-20
What I tried
date 2020-12-31 12-31-20
- I thought it depends on the locale setting of the server, so I added the following code before the conversion process mentioned above, but the result did not change ...
Supplementary information (FW/tool version, etc.)
Answer # 1
Date data imported by PHPExcel needs to be converted.
// $serial = PHP Date data read from Excel $fdate = gmadate ('Y-m-d', $serial * 60 * 60 * 24);
Converted like this
Others have pointed out, but I recommend switching to PhpSpreadSheet from now on. There are many parts of how to write code that are similar to PHP Excel.
- about exporting excel with php
- php - about the multiple structure of laravel's many-to-many relations
- about php zend framework flashmessenger
- about the operation of excel using python
- php - laravel get information about the user who clicked
- php - about laravel's associative array
- php - about array curly braces
- php - about dockerfile
- excel - about printing (selection) of multiple sheets using openpyxl
- [php] about the relationship between the number of select statements and the reading speed
- php - about the speed of data transfer
- php - how to convert from excel to pdf using libreoffice on ec2
- about php date function
- about excel → json generation method from python
- cakephp/crud: about query parameter value retrieval
- php - [laravel] about the return type of the helper function view ()
- php - about bookmark function on the web
- php - about laravel 8x components