* be the third row if say for instance the second row is undefined.
* Call getRowNum() on each row if you care which one it is.
*/
- public Iterator<Row> rowIterator() {
+ @SuppressWarnings("unchecked")
+ public Iterator<Row> rowIterator() {
return (Iterator<Row>)(Iterator<? extends Row>) _rows.values().iterator();
}
}
protected void write(OutputStream out) throws IOException {
+ boolean setToNull = false;
if(worksheet.sizeOfColsArray() == 1) {
CTCols col = worksheet.getColsArray(0);
if(col.sizeOfColArray() == 0) {
+ setToNull = true;
// this is necessary so that we do not write an empty <cols/> item into the sheet-xml in the xlsx-file
// Excel complains about a corrupted file if this shows up there!
worksheet.setColsArray(null);
xmlOptions.setSaveSuggestedPrefixes(map);
worksheet.save(out, xmlOptions);
+
+ // Bug 52233: Ensure that we have a col-array even if write() removed it
+ if(setToNull) {
+ worksheet.addNewCols();
+ }
}
/**
sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed());
}
- // TODO: disabled as the fix for this had severe side-effects
- public void doNotRuntestColumnWidthPOI52233() throws Exception {
+ public void testColumnWidthPOI52233() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("hello world");
- assertEquals("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
- assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
+
+ sheet = workbook.createSheet();
+ sheet.setColumnWidth(4, 5000);
+ sheet.setColumnWidth(5, 5000);
+
+ sheet.groupColumn((short) 4, (short) 5);
+
+ accessWorkbook(workbook);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
stream.close();
}
+ accessWorkbook(workbook);
+ }
+
+ private void accessWorkbook(XSSFWorkbook workbook) {
+ workbook.getSheetAt(1).setColumnGroupCollapsed(4, true);
+ workbook.getSheetAt(1).setColumnGroupCollapsed(4, false);
+
assertEquals("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
- assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <- did throw IndexOutOfBoundsException before fixing the bug
+ assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
}
}