add testcase for https://bz.apache.org/bugzilla/show_bug.cgi?id=62906
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846489 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0aa9b34d08
commit
6b7e322227
@ -36,8 +36,8 @@ public class CreateTable {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
try (Workbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sheet = (XSSFSheet) wb.createSheet();
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sheet = wb.createSheet();
|
||||
|
||||
// Set which area the table should be placed in
|
||||
AreaReference reference = wb.getCreationHelper().createAreaReference(
|
||||
|
@ -4109,18 +4109,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
||||
int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1;
|
||||
|
||||
// the id could already be taken after insertion/deletion of different tables
|
||||
outerloop:
|
||||
while(true) {
|
||||
boolean loop = true;
|
||||
while(loop) {
|
||||
loop = false;
|
||||
for (PackagePart packagePart : getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType())) {
|
||||
String fileName = XSSFRelation.TABLE.getFileName(tableNumber);
|
||||
if(fileName.equals(packagePart.getPartName().getName())) {
|
||||
// duplicate found, increase the number and start iterating again
|
||||
tableNumber++;
|
||||
continue outerloop;
|
||||
loop = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber, false);
|
||||
|
@ -55,10 +55,7 @@ import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.apache.poi.ss.util.CellUtil;
|
||||
import org.apache.poi.ss.util.*;
|
||||
import org.apache.poi.util.LocaleUtil;
|
||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
@ -1993,12 +1990,11 @@ public final class TestXSSFSheet extends BaseTestXSheet {
|
||||
|
||||
@Test
|
||||
public void testGetHeaderFooterProperties() throws IOException {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sh = wb.createSheet();
|
||||
|
||||
XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
|
||||
assertNotNull(hfProp);
|
||||
|
||||
wb.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,9 +349,39 @@ public final class TestXSSFTable {
|
||||
IOUtils.closeQuietly(wb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableIds() throws IOException {
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sheet = wb.createSheet();
|
||||
|
||||
AreaReference reference1 = wb.getCreationHelper().createAreaReference(
|
||||
new CellReference(0, 0), new CellReference(2, 2));
|
||||
|
||||
XSSFTable table1 = sheet.createTable(reference1);
|
||||
|
||||
assertEquals(1, table1.getCTTable().getTableColumns().getTableColumnArray(0).getId());
|
||||
assertEquals(2, table1.getCTTable().getTableColumns().getTableColumnArray(1).getId());
|
||||
assertEquals(3, table1.getCTTable().getTableColumns().getTableColumnArray(2).getId());
|
||||
|
||||
assertEquals(1, table1.getCTTable().getId());
|
||||
|
||||
AreaReference reference2 = wb.getCreationHelper().createAreaReference(
|
||||
new CellReference(10, 10), new CellReference(12, 12));
|
||||
|
||||
XSSFTable table2 = sheet.createTable(reference2);
|
||||
|
||||
// these IDs dupplicate those from table1 and may be cause of https://bz.apache.org/bugzilla/show_bug.cgi?id=62906
|
||||
assertEquals(1, table2.getCTTable().getTableColumns().getTableColumnArray(0).getId());
|
||||
assertEquals(2, table2.getCTTable().getTableColumns().getTableColumnArray(1).getId());
|
||||
assertEquals(3, table2.getCTTable().getTableColumns().getTableColumnArray(2).getId());
|
||||
|
||||
assertEquals(2, table2.getCTTable().getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetArea() throws IOException {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sh = wb.createSheet();
|
||||
|
||||
AreaReference tableArea = new AreaReference("B10:D12", wb.getSpreadsheetVersion());
|
||||
@ -380,13 +410,12 @@ public final class TestXSSFTable {
|
||||
|
||||
assertEquals(2, table.getColumnCount());
|
||||
assertEquals(2, table.getRowCount());
|
||||
|
||||
IOUtils.closeQuietly(wb);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateColumn() {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
public void testCreateColumn() throws IOException {
|
||||
try (XSSFWorkbook wb = new XSSFWorkbook()) {
|
||||
XSSFSheet sh = wb.createSheet();
|
||||
|
||||
AreaReference tableArea = new AreaReference("A2:A3", wb.getSpreadsheetVersion());
|
||||
@ -415,8 +444,7 @@ public final class TestXSSFTable {
|
||||
assertEquals("Column B", table.getColumns().get(1).getName());
|
||||
assertEquals("Column C", table.getColumns().get(2).getName());
|
||||
assertEquals("Column D", table.getColumns().get(3).getName());
|
||||
|
||||
IOUtils.closeQuietly(wb);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
Loading…
Reference in New Issue
Block a user