Bug 50681 - Avoid exception in HSSFDataFormat.getDataFormatString()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1136352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67206e5450
commit
f9bbd32caf
@ -34,11 +34,12 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.8-beta4" date="2011-??-??">
|
||||
<action dev="poi-developers" type="add">50681 - Fixed autosizing columns beyond 255 character limit </action>
|
||||
<action dev="poi-developers" type="add">51374 - Fixed incorrect setting of lastPrinted OOXML core property </action>
|
||||
<action dev="poi-developers" type="fix">50681 - Avoid exceptions in HSSFDataFormat.getDataFormatString() </action>
|
||||
<action dev="poi-developers" type="fix">50681 - Fixed autosizing columns beyond 255 character limit </action>
|
||||
<action dev="poi-developers" type="fix">51374 - Fixed incorrect setting of lastPrinted OOXML core property </action>
|
||||
<action dev="poi-developers" type="add">51351 - Word to XSL-FO converter</action>
|
||||
<action dev="poi-developers" type="add">50458 - Fixed missing shapeId in XSSF drawings </action>
|
||||
<action dev="poi-developers" type="add">51339 - Fixed arithmetic rounding in formula evaluation </action>
|
||||
<action dev="poi-developers" type="fix">50458 - Fixed missing shapeId in XSSF drawings </action>
|
||||
<action dev="poi-developers" type="fix">51339 - Fixed arithmetic rounding in formula evaluation </action>
|
||||
<action dev="poi-developers" type="add">51356 - Support autoSizeColumn in SXSSF</action>
|
||||
<action dev="poi-developers" type="add">51335 - Parse picture goal and crop sizes in HWPF</action>
|
||||
<action dev="poi-developers" type="add">51305 - Add sprmTCellPaddingDefault support in HWPF</action>
|
||||
|
@ -143,7 +143,13 @@ public final class HSSFDataFormat implements DataFormat {
|
||||
return _formats.get(index);
|
||||
}
|
||||
|
||||
String fmt = _formats.get(index);
|
||||
if(index == -1) {
|
||||
// YK: formatIndex can be -1, for example, for cell in column Y in test-data/spreadsheet/45322.xls
|
||||
// return null for those
|
||||
return null;
|
||||
}
|
||||
|
||||
String fmt = _formats.size() > index ? _formats.get(index) : null;
|
||||
if (_builtinFormats.length > index && _builtinFormats[index] != null) {
|
||||
// It's in the built in range
|
||||
if (fmt != null) {
|
||||
|
@ -19,9 +19,8 @@ package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.ss.usermodel.BaseTestDataFormat;
|
||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
|
||||
/**
|
||||
* Tests for {@link HSSFDataFormat}
|
||||
@ -49,4 +48,24 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
|
||||
assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
|
||||
assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 51378: getDataFormatString method call crashes when reading the test file
|
||||
*/
|
||||
public void test51378(){
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("12561-1.xls");
|
||||
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
|
||||
HSSFSheet sheet = wb.getSheetAt(i);
|
||||
for (Row row : sheet) {
|
||||
for (Cell cell : row) {
|
||||
CellStyle style = cell.getCellStyle();
|
||||
|
||||
String fmt = style.getDataFormatString();
|
||||
if(fmt == null)
|
||||
System.out.println(cell + ": " + fmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user