aVadim483 / fast-excel-reader

Lightwight and very fast XLSX Excel Spreadsheet Reader in PHP
MIT License
63 stars 16 forks source link

Differentiate timestamp and integer #9

Closed gerritwitkamp closed 1 year ago

gerritwitkamp commented 1 year ago

Hi,

I want all cell values to be strings, excepts dates values; they should be an instance of DateTime. Following the docs a date value is converted to a timestamp (integer), but that way I can't differentiate them from other integer cell values.

One way I could think of is extending the Excel class and override the formatDate method to return a DateTime instance. Or maybe I can identify a date value using the readRowsWithStyles?

Furthermore small question; can i force the row array to be as much as columns as the (first) headers row (filled with empty strings for example)? Used the following trick

foreach ($this->sheet->nextRow([], Excel::KEYS_ZERO_BASED) as $row) { yield array_replace(array_fill_keys(range(0, $this->nrOfCols), ''), array_map(fn($value) => $value instanceof \DateTime ? $value : (string) $value, $row)); }

Thanks in advance.

aVadim483 commented 1 year ago
  1. I'll add a dateFormatter() method where you can set your own date handler. I think this will be the best solution

  2. Good question. I think it would be logical to fill the row in two cases:

    • If a column range is set setReadArea('a:f');
    • If the first row is given as keys - Excel::KEYS_FIRST_ROW
aVadim483 commented 1 year ago

Done in v2.8.0