Bug 58461

Summary: setDefaultColumnStyle() isn't applied to new cells without explicit style (only XSSF)
Product: POI Reporter: Raimund <privat4>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 3.13-dev   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Full test case; creates a file first per HSSF, then per XSSF to show the different Excel behaviour

Description Raimund 2015-09-26 16:53:22 UTC
Created attachment 33149 [details]
Full test case; creates a file first per HSSF, then per XSSF to show the different Excel behaviour

1. Applying default column style by Sheet.setDefaultColumnStyle
2. Adding new Cell; but don't set an explicit cell style

==> the default column style seems to be not applied if opening the file with MS Excel 2010.

* Notes:
a) This works if using a HSSFWorkbook.
b) Strange: LibreOffice 4.3.7.2 displays the file as expected.
c) Maybe Bug 51037 deals with the same problem, but the description there is to imprecise to reproduce it.

* Code snippet:
  Workbook workbook = new XSSFWorkbook();
  Sheet sheet = workbook.createSheet();

  // Set default column style to user formatted time & yellow background
  CellStyle style = workbook.createCellStyle();
  style.setDataFormat(workbook.createDataFormat().getFormat("hh:mm:ss"));
  style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
  style.setFillPattern(CellStyle.SOLID_FOREGROUND);
  sheet.setDefaultColumnStyle(0, style);

  // Create one cell; cell contains actual date & time ...
  Row row = sheet.createRow(0);
  row.createCell(0).setCellValue(Calendar.getInstance());

* Results when viewing with MS Excel 2010:
The HSSF-file shows all cells - including the filled one - with yellow background and formatted as time.
In the XSSF-file the filled cell has neither a background color nor a cell format; the other cells of the column are formatted correctly.

Full test case appended; creates a file per HSSF & XSSF to show the differences of Excel behaviour.
Comment 1 Dominik Stadler 2015-09-30 12:11:18 UTC
I'll close this as duplicate of bug 51037 and comment some information from this bug there to not loose it.

*** This bug has been marked as a duplicate of bug 51037 ***