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:
parent
92a6e4538b
commit
2765285706
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<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">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">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>
|
<action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<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">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">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>
|
<action dev="POI-DEVELOPERS" type="add">35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version</action>
|
||||||
|
@ -278,21 +278,23 @@ public class HSSFCellStyle
|
|||||||
* Get the contents of the format string, by looking up
|
* Get the contents of the format string, by looking up
|
||||||
* the DataFormat against the bound workbook
|
* the DataFormat against the bound workbook
|
||||||
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
|
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
|
||||||
|
* @return the format string or "General" if not found
|
||||||
*/
|
*/
|
||||||
public String getDataFormatString() {
|
public String getDataFormatString() {
|
||||||
HSSFDataFormat format = new HSSFDataFormat(workbook);
|
return getDataFormatString(workbook);
|
||||||
|
|
||||||
return format.getFormat(getDataFormat());
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the contents of the format string, by looking up
|
* Get the contents of the format string, by looking up
|
||||||
* the DataFormat against the supplied workbook
|
* the DataFormat against the supplied workbook
|
||||||
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
|
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
|
||||||
|
*
|
||||||
|
* @return the format string or "General" if not found
|
||||||
*/
|
*/
|
||||||
public String getDataFormatString(Workbook workbook) {
|
public String getDataFormatString(Workbook workbook) {
|
||||||
HSSFDataFormat format = new HSSFDataFormat(workbook);
|
HSSFDataFormat format = new HSSFDataFormat(workbook);
|
||||||
|
|
||||||
return format.getFormat(getDataFormat());
|
int idx = getDataFormat();
|
||||||
|
return idx == -1 ? "General" : format.getFormat(getDataFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1851,9 +1851,7 @@ public final class HSSFSheet {
|
|||||||
} else {
|
} else {
|
||||||
String sval = null;
|
String sval = null;
|
||||||
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
|
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
|
||||||
HSSFDataFormat dataformat = wb.createDataFormat();
|
String format = style.getDataFormatString().replaceAll("\"", "");
|
||||||
short idx = style.getDataFormat();
|
|
||||||
String format = dataformat.getFormat(idx).replaceAll("\"", "");
|
|
||||||
double value = cell.getNumericCellValue();
|
double value = cell.getNumericCellValue();
|
||||||
try {
|
try {
|
||||||
NumberFormat fmt;
|
NumberFormat fmt;
|
||||||
|
BIN
src/testcases/org/apache/poi/hssf/data/45322.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/45322.xls
Normal file
Binary file not shown.
@ -1353,4 +1353,13 @@ public final class TestBugs extends TestCase {
|
|||||||
// TODO - check the formula once tables and
|
// TODO - check the formula once tables and
|
||||||
// arrays are properly supported
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user