fixed bug #45322: HSSFSheet.autoSizeColumn() throws NPE when cell number format was not found

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@676995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2008-07-15 18:13:50 +00:00
parent 92a6e4538b
commit 2765285706
6 changed files with 18 additions and 7 deletions

View File

@ -37,6 +37,7 @@
<!-- 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>

View File

@ -34,6 +34,7 @@
<!-- 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>

View File

@ -278,21 +278,23 @@ public class HSSFCellStyle
* 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());
}
/**

View File

@ -1851,9 +1851,7 @@ public final class HSSFSheet {
} 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;

Binary file not shown.

View File

@ -1353,4 +1353,13 @@ public final class TestBugs extends TestCase {
// 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);
}
}