Forum


Replies: 3   Views: 469
Get the style and format from a cell
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpxlsx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpxlsx version and check the Documentation available.

Posted by jeroen8087  · 02-02-2023 - 15:53

Is there a way to get the current style and format from an existing cell? For example: bold text and format as date.

Posted by admin  · 03-02-2023 - 12:49

Hello,

getCell returns information from a cell position. It doesn't return styles, but Indexer returns more information.

In future releases new methods and options to get more information will be added.

Regards.

Posted by jeroen8087  · 08-02-2023 - 09:24

Thank you for your reply.

In general this is not a real issue, except for cells representing a date. A cell containing a date has a numeric value. Example:

// Cell A1 contains the date 01-01-2023, with cell type "date"
$cellContents = $xlsx->getCell("A1");

echo $cellContents["value"];
// this gives the integer 44927



// Cell A2 contains the number 44927, with cell type "number"
$cellContents = $xlsx->getCell("A2");

echo $cellContents["value"];
// this gives the integer 44927

Converting 44927 to 01-01-2023 is not hard knowing the Excel 1900 date format. But, without knowing the cell format, we do not know if the value represents a date or an integer.

Posted by admin  · 08-02-2023 - 14:49

Hello,

Yes, the case you detail can't be detected, because both values use the same data, a number. In both cases MS Excel sets a number, and the display format is set using the numFmtId attribute of the styles file:

https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_numFmt_topic_ID0EHDH6.html

There's no method in the current stable version of phpxlsx to return this information. We have opened a task to add support.

Regards.