Bug 56524 - XSSFSheet.getColumnStyle doesn't conform to Sheet.getColumnStyle API doc
Summary: XSSFSheet.getColumnStyle doesn't conform to Sheet.getColumnStyle API doc
Status: RESOLVED DUPLICATE of bug 56525
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-14 17:30 UTC by Tim Meagher
Modified: 2014-05-14 17:37 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Meagher 2014-05-14 17:30:13 UTC
The XSSFSheet.getColumnStyle behaves differently than the corresponding method on HSSFSheet & what the API doc for Sheet says it should do.


The javadoc for org.apache.poi.ss.usermodel.Sheet states for getColumnStyle(int):

"Returns the CellStyle that applies to the given (0 based) column, or null if no style has been set for that column"

For XSSFSheet, however, if no cell style has been set for the column, then a new style is created and returned.
HSSFSheet conforms to the API doc, whereas XSSFSheet does not.

Reasoning/Why this causes problems:
Essentially, I want to use a Excel file as a "template" (though not a xlt/xltx, just a normal xls/xlsx) and write to a new spreadsheet, just taking the formatting from the template. If the "template" spreadsheet contains cell formatting, I want to preserve that formatting. In order to do this, I need to check if there is a style applied on the existing cell, then row, then column - although I guess the row then column ordering doesn't matter.
According to the API, I should just be able to check if, in the template, the "template"'s Sheet.getColumnStyle(col) returns null.
However if it came from an XLSX format, then the XSSFSheet will always return a style, which I then have to compare against what is returned from Workbook.createCellStyle to see if this is different from the default before working out if there really was a cell style applied for this column.

Also, it just breaks the API contract doesn't it?
Comment 1 Tim Meagher 2014-05-14 17:37:32 UTC
Sorry, my mistake.
Constructed a second bug after I got an error back from bugzilla while trying to create the first time. Second one (56525) contains a touch more info, so closing this one as a dup.

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