You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Blake Watson <bl...@pnmac.com> on 2016/10/05 23:56:43 UTC
Linking External Workbooks
Hey, POI-holloi:
I've got spreadsheets that link to other spreadsheets (created in Excel,
I'm just reading), and I wish to evaluate these spreadsheets in POI. If I
understand this StackExchange exchange correctly:
http://stackoverflow.com/questions/35093505/java-poi-xssf-vlookup-formula/35145903
This should be possible for me because I'm not trying to create the link,
it was already created in Excel. Despite doing what I think this poster has
described, I'm stuck with "Invalid sheetIndex: -1." errors.
So, the first question is: If everything is set up okay in the XSSF Formula
Evaluator, will evaluateFormulaCell actually return the result from the
other workbook? And the second question (if the answer to the first
question is "yes") is: How do I set it up correctly?
Here's what I'm doing now:
1. Open workbook 1.
2. Open workbook 2.
3. Check contents of externally calculated cell:
"VLOOKUP(PropertyState,'[1]Sheet'!$A:$B,2,FALSE)" = 2206.0
4. Create evaluator for workbook 2.
5. Create evaluator for workbook 1.
6. Call setupReferenceWorkbooks for wb1's evaluator, passing in the name of
the current wb attached to wb1's evaluator and the name of wb2 attached to
wb2's evaluator, double-checking that the latter in particular matches the
actual name used in the spreadsheet.
7. Vall evaluatorFormulaCell on the cell checked in step 3 and get:
IllegalArgumentException Invalid sheetIndex: -1.
org.apache.poi.ss.formula.SheetRefEvaluator.<init>
(SheetRefEvaluator.java:36)
I've also tried putting in "[1]" or "1" in the map rather than my
spreadsheet name. I don't see in all this how the spreadsheet name in Excel
comes out as "[1]" in POI.
Looking at SheetRefEvaluator hasn't been as enlightening as I hoped.
Anyone?
--
*Blake Watson*
*PNMAC*
Application Development Manager
5898 Condor Drive
Moorpark, CA 93021
(805) 330.4911 x7742
blake.watson@pnmac.com <me...@pnmac.com>
www.PennyMacUSA.com <http://www.pennymacusa.com/>
Re: Linking External Workbooks
Posted by Blake Watson <bl...@pnmac.com>.
So, I've got this working now, thanks again. When I did my simple test, I
noticed that a formula evaluator (which is documented as keeping "a cache
of all previously calculated intermediate cell values") actually keeps ALL
values around, whether they were calculated or just entered. So, if I did
the process in this order:
1. Create the evaluator for wb1
2. Change a value in wb1
3. Evaluate wb2 (which references wb1)
Values in wb2 would be calculated as though step 2 had never taken place.
If true, that's potentially very useful and worth documenting. (In my case,
it means I can keep formula evaluators cached as references without caring
whether other threads might change the base workbooks for their own
purposes.)
On Thu, Oct 6, 2016 at 11:12 AM, Nick Burch <ap...@gagravarr.org> wrote:
> On Thu, 6 Oct 2016, Blake Watson wrote:
>
>> That's just how Excel stores it for XLSX files. The link table provides
>>> the mapping between those indexes and the names shown in Excel. When POI
>>> hits one of those, it goes to the link table to find the name of the
>>> file,
>>> then checks for a setup referenced workbook with that name to resolve
>>> things with
>>>
>>
>> So, when POI sees the [1] how does it know that that should map to
>> "myspreadsheet.xlsx"? Because the setupReferencedWorkbooks map is
>> "name"->evaluator. I feel like not knowing this is the key to my
>> confusion.
>>
>
> The name to ID mapping is stored in the ExternalLinksTable, which comes
> from another xml file within the .xlsx bundle. That's what POI uses to
> lookup the name, and what Excel transparently uses when displaying the
> formula
>
> Nick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
--
*Blake Watson*
*PNMAC*
Application Development Manager
5898 Condor Drive
Moorpark, CA 93021
(805) 330.4911 x7742
blake.watson@pnmac.com <me...@pnmac.com>
www.PennyMacUSA.com <http://www.pennymacusa.com/>
Re: Linking External Workbooks
Posted by Blake Watson <bl...@pnmac.com>.
Thanks again, Nick!
On Thu, Oct 6, 2016 at 11:12 AM, Nick Burch <ap...@gagravarr.org> wrote:
> On Thu, 6 Oct 2016, Blake Watson wrote:
>
>> That's just how Excel stores it for XLSX files. The link table provides
>>> the mapping between those indexes and the names shown in Excel. When POI
>>> hits one of those, it goes to the link table to find the name of the
>>> file,
>>> then checks for a setup referenced workbook with that name to resolve
>>> things with
>>>
>>
>> So, when POI sees the [1] how does it know that that should map to
>> "myspreadsheet.xlsx"? Because the setupReferencedWorkbooks map is
>> "name"->evaluator. I feel like not knowing this is the key to my
>> confusion.
>>
>
> The name to ID mapping is stored in the ExternalLinksTable, which comes
> from another xml file within the .xlsx bundle. That's what POI uses to
> lookup the name, and what Excel transparently uses when displaying the
> formula
>
> Nick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
--
*Blake Watson*
*PNMAC*
Application Development Manager
5898 Condor Drive
Moorpark, CA 93021
(805) 330.4911 x7742
blake.watson@pnmac.com <me...@pnmac.com>
www.PennyMacUSA.com <http://www.pennymacusa.com/>
Re: Linking External Workbooks
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 6 Oct 2016, Blake Watson wrote:
>> That's just how Excel stores it for XLSX files. The link table provides
>> the mapping between those indexes and the names shown in Excel. When POI
>> hits one of those, it goes to the link table to find the name of the file,
>> then checks for a setup referenced workbook with that name to resolve
>> things with
>
> \u200bSo, when POI sees the [1] how does it know that that should map to
> "myspreadsheet.xlsx"? Because the setupReferenced\u200bWorkbooks map is
> "name"->evaluator. I feel like not knowing this is the key to my confusion.
The name to ID mapping is stored in the ExternalLinksTable, which comes
from another xml file within the .xlsx bundle. That's what POI uses to
lookup the name, and what Excel transparently uses when displaying the
formula
Nick
Re: Linking External Workbooks
Posted by Blake Watson <bl...@pnmac.com>.
Thanks for the assist, Nick!
> >
> That's just how Excel stores it for XLSX files. The link table provides
> the mapping between those indexes and the names shown in Excel. When POI
> hits one of those, it goes to the link table to find the name of the file,
> then checks for a setup referenced workbook with that name to resolve
> things with
>
So, when POI sees the [1] how does it know that that should map to
"myspreadsheet.xlsx"? Because the setupReferencedWorkbooks map is
"name"->evaluator. I feel like not knowing this is the key to my confusion.
> Take a look at
>
> TestXSSFFormulaEvaluation method
>
> testReferencesToOtherWorkbooks() + referenced test files for how it ought
> to work
>
Looking at that now. I notice that the test doesn't actually change any
values, it just checks to see that the value is the same in the referencing
spreadsheet before and after.
>
> Can you create two very simple workbooks, both with 2 sheets, one with a
> handful of data cells in, the other with your formula, which shows the
> problem? If so, please upload them to bugzilla along with a small junit
> unit test, and we'll take a look
>
> The simple case doesn't return this so I must have introduced another
issue. If it recurs and I can recreate, I'll file a bugzilla report.
--
*Blake Watson*
*PNMAC*
Application Development Manager
5898 Condor Drive
Moorpark, CA 93021
(805) 330.4911 x7742
blake.watson@pnmac.com <me...@pnmac.com>
www.PennyMacUSA.com <http://www.pennymacusa.com/>
Re: Linking External Workbooks
Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 5 Oct 2016, Blake Watson wrote:
> I've also tried putting in "[1]" or "1" in the map rather than my
> spreadsheet name. I don't see in all this how the spreadsheet name in Excel
> comes out as "[1]" in POI.
That's just how Excel stores it for XLSX files. The link table provides
the mapping between those indexes and the names shown in Excel. When POI
hits one of those, it goes to the link table to find the name of the file,
then checks for a setup referenced workbook with that name to resolve
things with
Take a look at TestXSSFFormulaEvaluation method
testReferencesToOtherWorkbooks() + referenced test files for how it ought
to work
> 7. Vall evaluatorFormulaCell on the cell checked in step 3 and get:
> IllegalArgumentException Invalid sheetIndex: -1.
> org.apache.poi.ss.formula.SheetRefEvaluator.<init>
> (SheetRefEvaluator.java:36)
That doesn't look like the normal error for missing linked workbooks, so
there might be a bug
Can you create two very simple workbooks, both with 2 sheets, one with a
handful of data cells in, the other with your formula, which shows the
problem? If so, please upload them to bugzilla along with a small junit
unit test, and we'll take a look
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org