Search code examples
referenceexternalapache-poi

apache poi how to disable external reference or external links?


I've been looking on the web for 30 minutes now and can't find any explanation about that. Here is my problem :

I wrote an application with poi to parse some data from 200 excel files or so and put some of it into a new file. I do some cell evaluation with FormulaEvaluator to know the content of the cells before choosing to keep them or not.
Now, when i test it on a test file with only values in the cells, the program works perfectly but when i use it on my pile of files I get this error :

"could not resolve external workbook name"

Is there any way to ignore external workbook references or set up the environment so that it wont evaluate formula with external references?
Because the ones I need don't contain references...

Thank you


Solution

  • Can you not just catch the error, and skip over that cell?

    You're getting the error because you've asked POI to evaluate a the formula in a cell, and that formula refers to a different file. However, you've not told POI where to find the file that's referenced, so it objects.

    If you don't care about cells with external references, just catch the exception and move on to the next cell.

    If you do care, you'll need to tell POI where to find your files. You do this with the setupEnvironment(String[],Evaluator[]) method - pass it an array of workbook names, and a matching array of evaluators for those workbooks.