}
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(
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;
/**
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);
// 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++) {