Bug 50681 - Fixed autosizing columns beyond 255 character limit
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1136330 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cbb3176c72
commit
67206e5450
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta4" date="2011-??-??">
|
<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="add">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">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">50458 - Fixed missing shapeId in XSSF drawings </action>
|
||||||
|
@ -1764,7 +1764,16 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
*/
|
*/
|
||||||
public void autoSizeColumn(int column, boolean useMergedCells) {
|
public void autoSizeColumn(int column, boolean useMergedCells) {
|
||||||
double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
|
double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
|
||||||
if(width != -1) setColumnWidth(column, (int) (256*width));
|
|
||||||
|
if (width != -1) {
|
||||||
|
width *= 256;
|
||||||
|
int maxColumnWidth = 255*256; // The maximum column width for an individual cell is 255 characters
|
||||||
|
if (width > maxColumnWidth) {
|
||||||
|
width = maxColumnWidth;
|
||||||
|
}
|
||||||
|
setColumnWidth(column, (int)(width));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -381,10 +381,15 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
public void autoSizeColumn(int column, boolean useMergedCells) {
|
public void autoSizeColumn(int column, boolean useMergedCells) {
|
||||||
double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
|
double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
|
||||||
if(width != -1){
|
|
||||||
|
if (width != -1) {
|
||||||
|
width *= 256;
|
||||||
|
int maxColumnWidth = 255*256; // The maximum column width for an individual cell is 255 characters
|
||||||
|
if (width > maxColumnWidth) {
|
||||||
|
width = maxColumnWidth;
|
||||||
|
}
|
||||||
|
setColumnWidth(column, (int)(width));
|
||||||
columnHelper.setColBestFit(column, true);
|
columnHelper.setColBestFit(column, true);
|
||||||
columnHelper.setCustomWidth(column, true);
|
|
||||||
columnHelper.setColWidth(column, width);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,4 +306,24 @@ public abstract class BaseTestBugzillaIssues extends TestCase {
|
|||||||
fmla.append(")");
|
fmla.append(")");
|
||||||
return fmla.toString();
|
return fmla.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void testAutoSize_bug506819() {
|
||||||
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet("Sheet1");
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
Cell cell0 = row.createCell(0);
|
||||||
|
|
||||||
|
String longValue = "www.hostname.com, www.hostname.com, " +
|
||||||
|
"www.hostname.com, www.hostname.com, www.hostname.com, " +
|
||||||
|
"www.hostname.com, www.hostname.com, www.hostname.com, " +
|
||||||
|
"www.hostname.com, www.hostname.com, www.hostname.com, " +
|
||||||
|
"www.hostname.com, www.hostname.com, www.hostname.com, " +
|
||||||
|
"www.hostname.com, www.hostname.com, www.hostname.com, www.hostname.com";
|
||||||
|
|
||||||
|
cell0.setCellValue(longValue);
|
||||||
|
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
assertEquals(255*256, sheet.getColumnWidth(0)); // maximum column width is 255 characters
|
||||||
|
sheet.setColumnWidth(0, sheet.getColumnWidth(0)); // Bug 506819 reports exception at this point
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user