Sagar Singh
Sagar Singh

Reputation: 13

How to get PHPExcel cell format

I am reading an excel file using PHPExcel. I want to know if there is way to know the cells format. Eg: no.of decimal places, if % or number etc.

Upvotes: 0

Views: 1696

Answers (1)

Mark Baker
Mark Baker

Reputation: 212522

You can read the number format mask for a cell by doing:

$objPHPExcel->getActiveSheet()
    ->getStyle('A1')
    ->getNumberFormat()
    ->getFormatCode();

which will return the formatting mask as a string

e.g

'£#,##0;-£#,##0'

or

'0.00%'

but PHPExcel provides no functionality to interpret this mask to show whether it is a percentage or how many decimals should be shown; you'd need to add that logic yourself; although you could possibly extract some of the logic for interpreting it from the code for the toFormattedString() method in PHPExcel_Style_NumberFormat

Upvotes: 2

Related Questions