<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="add">51351 - Word to XSL-FO converter</action>
<action dev="poi-developers" type="add">50458 - Fixed missing shapeId in XSSF drawings </action>
*/
public void autoSizeColumn(int column, boolean 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));
+ }
+
}
/**
*/
public void autoSizeColumn(int column, boolean 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.setCustomWidth(column, true);
- columnHelper.setColWidth(column, width);
}
}
fmla.append(")");
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
+ }
}