Bug 50681 - autoSizeColumn sets column width beyond 255 character limit for XSSF sheets and HSSF Sheets
Summary: autoSizeColumn sets column width beyond 255 character limit for XSSF sheets a...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-28 11:48 UTC by bryan_coleman
Modified: 2011-06-16 08:59 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bryan_coleman 2011-01-28 11:48:52 UTC
Using version 3.7

XSSFSheet.autoSizeColumn calculates the size of a large column beyond the 255 character maximum.  The HSSFSheet.autoSizeColumn does not do this.  I noticed that bug 50211 combined the XSSF and HSSF autoSizeColumn methods.  I have not tried the latest developer release; however, I wanted to get this in there to make sure this bug isn't carried over from the XSSF class.

To reproduce:

import org.apache.poi.xssf.usermodel.*;
import java.io.*;

public class AutoSizeTest {

    public static void main(String args[]) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet    sheet = workbook.createSheet("");
        XSSFRow      row = sheet.createRow(0);
        XSSFCell     cell0 = row.createCell(0);

        cell0.setCellValue("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");

        sheet.autoSizeColumn(0);
        sheet.setColumnWidth(0, sheet.getColumnWidth(0)); // FAILS HERE

        try {
            FileOutputStream out = new FileOutputStream("working.xls");
            workbook.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } // main
}
Comment 1 Nick Burch 2011-01-28 11:56:34 UTC
Please re-test with a recent svn checkout / nightly build and confirm if the problem is there or not.
Comment 2 bryan_coleman 2011-02-07 14:50:58 UTC
I do not have available time in the near future to test with the latest code base.  If anyone has time available, please test using the code provided.  If there is a jar that I can just drop into my application, I would probably have the fifteen minutes to try that within the next few weeks just let me know where to find it.
Comment 3 jxz164 2011-06-15 20:44:06 UTC
I have tested the above code in 3.8 beta 3 and it failed.

There is also a regression for HSSF Sheets.

The following code works in POI 3.7, but fails in POI 3.8 beta3.

package org.apache.poi.ss.examples;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

import java.io.*;

public class AutoSizeTest {

    public static void main(String args[]) {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet    sheet = workbook.createSheet("Sheet1");
        HSSFRow      row = sheet.createRow(0);
        HSSFCell     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);
        sheet.setColumnWidth(0, sheet.getColumnWidth(0)); // FAILS HERE

        try {
            FileOutputStream out = new FileOutputStream("C:/workspace/working.xls");
            workbook.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } // main
}
Comment 4 Yegor Kozlov 2011-06-16 08:59:15 UTC
Fixed in r1136330, junit added.

Yegor