]> source.dussan.org Git - poi.git/commitdiff
The Event User Model fake-workbook for formula evaluations needs to know about the...
authorNick Burch <nick@apache.org>
Sat, 19 Jul 2014 19:10:47 +0000 (19:10 +0000)
committerNick Burch <nick@apache.org>
Sat, 19 Jul 2014 19:10:47 +0000 (19:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611946 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java
src/java/org/apache/poi/ss/formula/ptg/ExternSheetNameResolver.java
src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java

index c6036d658268aaa2a0cd7981948704e8710b538b..b0d0388a2c9801d585f22074c6fcde0ab10e5f3d 100644 (file)
@@ -138,7 +138,14 @@ public class EventWorkbookBuilder {
                }
 
                public HSSFWorkbook getStubHSSFWorkbook() {
-                       return HSSFWorkbook.create(getStubWorkbook());
+                   // Create a base workbook
+                   HSSFWorkbook wb = HSSFWorkbook.create(getStubWorkbook());
+                   // Stub the sheets, so sheet name lookups work
+                   for (BoundSheetRecord bsr : boundSheetRecords) {
+                       wb.createSheet(bsr.getSheetname());
+                   }
+                   // Ready for Formula use!
+                   return wb;
                }
                public InternalWorkbook getStubWorkbook() {
                        return createStubWorkbook(
index 150bd99e790a974453219c77e9028ff729fde406..be20167ed9164176031f4d7f39e49a7514f972e3 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.poi.ss.formula.ptg;
 
-import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
 import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
+import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
 import org.apache.poi.ss.formula.SheetNameFormatter;
 
 /**
@@ -36,8 +36,13 @@ final class ExternSheetNameResolver {
                if (externalSheet != null) {
                        String wbName = externalSheet.getWorkbookName();
                        String sheetName = externalSheet.getSheetName();
-                       sb = new StringBuffer(wbName.length() + sheetName.length() + cellRefText.length() + 4);
-                       SheetNameFormatter.appendFormat(sb, wbName, sheetName);
+                       if (wbName != null) {
+                       sb = new StringBuffer(wbName.length() + sheetName.length() + cellRefText.length() + 4);
+                       SheetNameFormatter.appendFormat(sb, wbName, sheetName);
+                       } else {
+                sb = new StringBuffer(sheetName.length() + cellRefText.length() + 4);
+                SheetNameFormatter.appendFormat(sb, sheetName);
+                       }
                } else {
                        String sheetName = book.getSheetNameByExternSheet(field_1_index_extern_sheet);
                        sb = new StringBuffer(sheetName.length() + cellRefText.length() + 4);
index 552afca9dbffe95e6516f472986a3e6f4d3905e4..e7869755a96b67a65b3c1ee2ed6c97c2ab1c7d03 100644 (file)
@@ -97,8 +97,11 @@ public final class TestEventWorkbookBuilder extends TestCase {
 
                // Check these stubs have the right stuff on them
                assertEquals("Sheet1", stubWB.getSheetName(0));
-               assertEquals("S2", stubWB.getSheetName(1));
-               assertEquals("Sh3", stubWB.getSheetName(2));
+        assertEquals("Sheet1", stubHSSF.getSheetName(0));
+               assertEquals("S2",     stubWB.getSheetName(1));
+        assertEquals("S2",     stubHSSF.getSheetName(1));
+               assertEquals("Sh3",    stubWB.getSheetName(2));
+        assertEquals("Sh3",    stubHSSF.getSheetName(2));
 
                // Check we can get the formula without breaking
                for(int i=0; i<fRecs.length; i++) {