Browse Source

fix a condition not seen until a recent expansion of the stress test. Gracefully ignore missing/invalid external sheet references in one more path (there were several already with comments like "this seems to be what Excel does in this case")

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1856655 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_4_1_0
Greg Woolsey 5 years ago
parent
commit
48ac6b4d02

+ 1
- 1
src/java/org/apache/poi/ss/formula/SheetNameFormatter.java View File

@@ -179,7 +179,7 @@ public final class SheetNameFormatter {

int len = rawSheetName.length();
if(len < 1) {
throw new RuntimeException("Zero length string is an invalid sheet name");
return false; // some cases we get missing external references, resulting in empty sheet names
}
if(Character.isDigit(rawSheetName.charAt(0))) {
// sheet name with digit in the first position always requires delimiting

+ 14
- 0
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java View File

@@ -17,9 +17,12 @@

package org.apache.poi.hssf.usermodel;

import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.formula.EvaluationSheet;
import org.apache.poi.ss.usermodel.BaseTestXEvaluationSheet;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Sheet;
import org.junit.Test;

import java.util.AbstractMap;
import java.util.Map;
@@ -30,4 +33,15 @@ public class TestHSSFEvaluationSheet extends BaseTestXEvaluationSheet {
HSSFSheet sheet = new HSSFWorkbook().createSheet();
return new AbstractMap.SimpleEntry<>(sheet, new HSSFEvaluationSheet(sheet));
}
@Test
public void testMissingExternalName() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("external_name.xls");
for (Name name : wb.getAllNames()) {
// this sometimes causes exceptions
if(!name.isFunctionName()) {
name.getRefersToFormula();
}
}
}
}

Loading…
Cancel
Save