I’m using getCalculatedValue() in my PHPExcel to read 34 Excel files. Unfortunately there were some users who put i:\drive\test[month.xls]$C$1 in the cell causing PHPExcel unable to read and store #REF! in the mysql.
I know that getCalculatedValue() will read formula in a cell, but how about link? Somemore, the link found in the Excel files are external link, which I couldn’t access.
Although the cell contain links to another worksheet, but on the cell itself displaying some value. The best solution is to copy all and paste value. But this seem not practical to open 34 Excel files for this purpose.
I appreciate someone can enlighten me.
Thanks.
The latest SVN code for PHPExcel will throw an exception if it encounters a reference to an external workbook. You can wrap your getCalculatedValue() call in a try/catch block, and if this exception is thrown use getOldCalculatedValue() to retrieve the result from when MS Excel itself last calculated this cell’s value.
A #REF! response may be a perfectly valid response from a formula, so it isn’t adequate simply to trap for that, which is why the Exception is thrown in this particular circumstance.
Note that this is not guaranteed – it is possible to disable automatic calculation in Excel, or for the referenced external workbooks to have been modified since the workbook you are reading was saved – in both these cases, getOldCalculatedValue() may return an erroneous result, and you have no way of knowing if this is the case… but it’s generally pretty accurate. The SVN code modifications were for precisely this reason, when I had the same situation for a client that I was working with back in December; and the code will be included within the 1.7.7 production release of PHPExcel that should be available by the end of this week.
EDIT