A
A
Anton2018-05-14 12:50:47
PHP
Anton, 2018-05-14 12:50:47

The date is incorrectly perceived when parsing an .xls file through phpexcel?

Good afternoon. Parsing .xls ,
I get a normal human array at the output, but that's not the point After working out phpexcel, +1 is added to the day of this date, i.e. 12 turns into 13, 20 into 21 If you change dots to dashes, slashes, etc. in excel. as a separator of days, months, years, then it is parsed normally, but with dots this is such a mystic. How to deal with it? Parsing code, just in case, although it shouldn't be needed
1I2IpK2TvzM.jpg

the code
function exceltohtml($file = NULL) {
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('utf-8');
    $data->setUTFEncoder('mb');

    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) {
       echo 'Необходимо залить файл настроек';
      die();
    }

    // 2. Проверка эксель пустой/не пустой
    $data->read($_SERVER['DOCUMENT_ROOT'] . $file);

    if (empty($data->sheets[0]['cells']) || !count($data->sheets[0]['cells'])) {
       echo 'Эксель файл некорректный или пустой';
       die();
    } else {
      $rows = $data->sheets[0]['cells'];
      return $rows;
    }		
    
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-05-14
@Eridani

I decided.
Found the function of forming the date and +1 to the day in reader.php
Removed, smelled.

function createDate($numValue)
    {
        if ($numValue > 1) {
            $utcDays = $numValue - ($this->nineteenFour ? SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904 : SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS);
            $utcValue = round(($utcDays) * SPREADSHEET_EXCEL_READER_MSINADAY);
            $string = date ($this->curformat, $utcValue);
            $raw = $utcValue;
        } else {
            $raw = $numValue;
            $hours = floor($numValue * 24);
            $mins = floor($numValue * 24 * 60) - $hours * 60;
            $secs = floor($numValue * SPREADSHEET_EXCEL_READER_MSINADAY) - $hours * 60 * 60 - $mins * 60;
            $string = date ($this->curformat, mktime($hours, $mins, $secs));
        }

        return array($string, $raw);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question