fixed XSSFSheet autoSizeColumn() to tolerate empty RichTextString, see Bugzilla 48332

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@887160 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-12-04 11:24:02 +00:00
parent c6bb12768d
commit 5d9a1169cd
3 changed files with 24 additions and 5 deletions

View File

@ -34,6 +34,7 @@
<changes> <changes>
<release version="3.6-beta1" date="2009-??-??"> <release version="3.6-beta1" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">48332 - fixed XSSFSheet autoSizeColumn() to tolerate empty RichTextString</action>
<action dev="POI-DEVELOPERS" type="fix">48332 - fixed ColumnInfoRecord to tolerate missing reserved field</action> <action dev="POI-DEVELOPERS" type="fix">48332 - fixed ColumnInfoRecord to tolerate missing reserved field</action>
<action dev="POI-DEVELOPERS" type="fix">47701 - fixed RecordFormatException when reading list subrecords (LbsDataSubRecord)</action> <action dev="POI-DEVELOPERS" type="fix">47701 - fixed RecordFormatException when reading list subrecords (LbsDataSubRecord)</action>
<action dev="POI-DEVELOPERS" type="add"> memory usage optimization in XSSF - avoid creating parentless xml beans</action> <action dev="POI-DEVELOPERS" type="add"> memory usage optimization in XSSF - avoid creating parentless xml beans</action>

View File

@ -366,11 +366,13 @@ public class ColumnHelper {
XSSFFont fnt = rt.getFontOfFormattingRun(j); XSSFFont fnt = rt.getFontOfFormattingRun(j);
if (fnt != null) { if (fnt != null) {
int len = rt.getLengthOfFormattingRun(j); int len = rt.getLengthOfFormattingRun(j);
if(len > 0) { //ignore degenerate zero-length runs
copyAttributes(fnt, str, pos, pos + len); copyAttributes(fnt, str, pos, pos + len);
pos += len; pos += len;
} }
} }
} }
}
layout = new TextLayout(str.getIterator(), frc); layout = new TextLayout(str.getIterator(), frc);
if(style.getRotation() != 0){ if(style.getRotation() != 0){

View File

@ -17,9 +17,7 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BaseTestSheet; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
@ -158,6 +156,24 @@ public class TestXSSFSheet extends BaseTestSheet {
assertTrue(col.getBestFit()); assertTrue(col.getBestFit());
} }
/**
* XSSFSheet autoSizeColumn() on empty RichTextString fails
*/
public void test48325() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Test");
CreationHelper factory = wb.getCreationHelper();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
XSSFFont font = wb.createFont();
RichTextString rts = factory.createRichTextString("");
rts.applyFont(font);
cell.setCellValue(rts);
sheet.autoSizeColumn(0);
}
public void testGetCellComment() { public void testGetCellComment() {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();