php - PHPExcel getFormatCode Issue

316

I am using PHPExcel to read data from Excel. It is not giving me proper cell number format even though I set it as date ('YYYY-MM-DD') format. The code I use

$reader = new PHPExcel_Reader_Excel5();
$reader->setReadDataOnly(true);
$PHPExcel = $reader->load($file );

$format = $PHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->getFormatCode();
var_dump($format);

I always get General. I don't know which column is going to be date format, so that part needs to be programmatically.

Thanks

123

Answer

Solution:

reader->setReadDataOnly(true);

means read only the raw data from the cells: don't read any of the formatting information

If you do

reader->setReadDataOnly(false);

then PHPExcel will read the formatting as well

People are also looking for solutions to the problem: javascript - Why won't my AJAX function correctly populate a drop-down list in Internet Explorer?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.