I have a workbook, which I must clear from all references to other workbooks. I am currently trying to parse the cell formulas wo check if they are referencing any excel file.
For that I use this line
cell.getCellFormula().matches(".*\\[.*\\.xls[xm]?\\].*")
the issue with this is, that the cell looks like this in XML format:
<c r="K64" s="2128">
<f>[5]Segments!$AS$7/Annual!AF38</f>
<v>0.0</v>
</c>
As you can see, the formula doesn't actually contain .xls
, '.xlsx' or .xlsm
at all. As far as I know [5]
indicates a shared string which holds the actual path and therefore the actual value for the formula.
Now one could say and change the regex to .*\\[\d+\\].*
, but I think that this can be pretty error prone. Also I think that not literally every external reference will look like this.
So my question is:
How can I identify formulas which reference an external workbook?
If you have any questions, feel free to ask.
EDIT:
I have prepared an sample excel file showcasing the issue. It's available for download at workupload.com
[5]
) to the reference – XtremeBaumerxl/sharedStrings.xml
the text should be in XML element/sst/si[5]/t
– Joop Eggen