Closed (fixed)
Project:
PHPExcel
Version:
7.x-3.7
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 Jun 2013 at 23:26 UTC
Updated:
27 Nov 2013 at 19:36 UTC
Jump to comment: Most recent
I'm trying to read in cell values, and in some cases the cell is defined by a formula and I'm reading in the formula, but I'd like to get the value.
For example, the formula is: =CONCATENATE(G2," ",D2," of ",E2)
but I'd like the 'rendered' cell, which is 1275x1200h Cost of production
Is there a way to tell PHPExcel to take the calculated value, rather than the 'raw' formula?
Thanks
Comments
Comment #1
wadmiraal commentedYes, but it does not provide this out of the box. The thing is that it's a bit tricky for PHPExcel to determine when to fetch the calculated value (what you're after) and when to fetch the text value (what it does by default).
You could just implement the import hook and listen to any cell that's been imported (
$op = 'post cell'). Then, you could check the string value of$data(ex: regular expression) and if you know this is a cell you want to process, just callgetCalculatedValue()on$phpexcel(which will contain the current cell) to alter$dataand get what you want.Example:
I haven't checked the code, but it should work. Let me know.
This is a duplicate of #1887652: Support for getCalculatedValue(), so I'll close it.
Comment #2
gaele commentedThanks, this seems to work. At least on MS files.
However if I let this run on an xls or xlsx file created by LibreOffice it throws this error:
PHPExcel_Calculation_Exception: Data!C6 -> Data!C6 -> Data!C6 -> Formula Error: An unexpected error occured in PHPExcel_Cell->getCalculatedValue() (line 298 of /sites/all/libraries/PHPExcel/Classes/PHPExcel/Cell.php).(Actually I used an xlsx file created by MS Office, read by and changed in LibreOffice, and than saved as either xls or xlsx by LibreOffice).
Do you have any idea of how to solve or circumvent this? Does PHP(Excel) have a method to check if a file is created by LibreOffice?
Comment #3
gaele commentedComment #4
wadmiraal commentedI have no idea, I'm sorry. I've never run into that error before. Have you checked the PHPExcel library issue queue ? Maybe someone else has had the same problem.
Comment #5
gaele commentedTurned out the error was already in the original file.
So the code above works fine.
Thanks for this nice module, BTW.