bug 57840: add test using a Data Table not anchored at A1

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-11 00:11:41 +00:00
parent b895003260
commit 1a906b4d68

View File

@ -117,13 +117,11 @@ public final class TestXSSFTable {
@Test @Test
public void findColumnIndex() throws IOException { public void findColumnIndex() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
// FIXME: use a worksheet where upper left cell of table is not A1 so that we test
// that XSSFTable.findColumnIndex returns the column index relative to the first
// column in the table, not the column number in the sheet
XSSFTable table = wb.getTable("\\_Prime.1"); XSSFTable table = wb.getTable("\\_Prime.1");
assertNotNull(table); assertNotNull(table);
assertEquals(0, table.findColumnIndex("calc='#*'#")); assertEquals("column header has special escaped characters",
0, table.findColumnIndex("calc='#*'#"));
assertEquals(1, table.findColumnIndex("Name")); assertEquals(1, table.findColumnIndex("Name"));
assertEquals(2, table.findColumnIndex("Number")); assertEquals(2, table.findColumnIndex("Number"));
@ -137,6 +135,21 @@ public final class TestXSSFTable {
wb.close(); wb.close();
} }
@Test
public void findColumnIndexIsRelativeToTableNotSheet() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("DataTableCities.xlsx");
XSSFTable table = wb.getTable("SmallCity");
// Make sure that XSSFTable.findColumnIndex returns the column index relative to the first
// column in the table, not the column number in the sheet
assertEquals(0, table.findColumnIndex("City")); // column I in worksheet but 0th column in table
assertEquals(1, table.findColumnIndex("Latitude"));
assertEquals(2, table.findColumnIndex("Longitude"));
assertEquals(3, table.findColumnIndex("Population"));
wb.close();
}
@Test @Test
public void getSheetName() throws IOException { public void getSheetName() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");