<!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45322 - Fixed NPE in HSSFSheet.autoSizeColumn() when cell number format was not found</action>
<action dev="POI-DEVELOPERS" type="add">45380 - Missing return keyword in ArrayPtg.toFormulaString()</action>
<action dev="POI-DEVELOPERS" type="add">44958 - Record level support for Data Tables. (No formula parser support though)</action>
<action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45322 - Fixed NPE in HSSFSheet.autoSizeColumn() when cell number format was not found</action>
<action dev="POI-DEVELOPERS" type="add">45380 - Missing return keyword in ArrayPtg.toFormulaString()</action>
<action dev="POI-DEVELOPERS" type="add">44958 - Record level support for Data Tables. (No formula parser support though)</action>
<action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
* Get the contents of the format string, by looking up
* the DataFormat against the bound workbook
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
+ * @return the format string or "General" if not found
*/
public String getDataFormatString() {
- HSSFDataFormat format = new HSSFDataFormat(workbook);
-
- return format.getFormat(getDataFormat());
+ return getDataFormatString(workbook);
}
/**
* Get the contents of the format string, by looking up
* the DataFormat against the supplied workbook
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
+ *
+ * @return the format string or "General" if not found
*/
public String getDataFormatString(Workbook workbook) {
HSSFDataFormat format = new HSSFDataFormat(workbook);
- return format.getFormat(getDataFormat());
+ int idx = getDataFormat();
+ return idx == -1 ? "General" : format.getFormat(getDataFormat());
}
/**
} else {
String sval = null;
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
- HSSFDataFormat dataformat = wb.createDataFormat();
- short idx = style.getDataFormat();
- String format = dataformat.getFormat(idx).replaceAll("\"", "");
+ String format = style.getDataFormatString().replaceAll("\"", "");
double value = cell.getNumericCellValue();
try {
NumberFormat fmt;
// TODO - check the formula once tables and
// arrays are properly supported
}
+
+ /**
+ * 45322: HSSFSheet.autoSizeColumn fails when style.getDataFormat() returns -1
+ */
+ public void test45322() throws Exception {
+ HSSFWorkbook wb = openSample("44958.xls");
+ HSSFSheet sh = wb.getSheetAt(0);
+ for(short i=0; i < 30; i++) sh.autoSizeColumn(i);
+ }
}