https://issues.apache.org/bugzilla/show_bug.cgi?id=48406

Bill Stackhouse <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #3 from Bill Stackhouse <[email protected]> 2010-03-15 18:47:49 
UTC ---
After setting all text cells in a column with mostly long upper case strings,
calling setAutoSize usually sets it to a width that is too narrow.

It appears that HSSFSheet.setAutoSize uses '0' as the default character width.
The Verdana Plain 10 font on the Macintosh has a width of 6. 'W' and 'm' both
are 10 and '%' is the widest at 11.

Shouldn't this be changed from '0' to '%' or loop through the FontMetrics of
the font to find the widest character?

BTW I do see it setting the width more correctly using Helvetica Plan 10, but
not with Arial Plain 10 which is the default font.


Sample source

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class AutoSize {

    public static void main(String[] args) {

        HSSFWorkbook workBook = new HSSFWorkbook();
        HSSFCellStyle style = workBook.createCellStyle();
        final HSSFFont font = workBook.createFont();
        font.setFontHeightInPoints((short) 10);
        font.setFontName("Verdana");
        style.setFont(font);
        HSSFSheet sheet = workBook.createSheet();
        HSSFRow row = sheet.createRow((short) 0);
        HSSFCell cell;

        cell = row.createCell(0);
        cell.setCellValue("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        cell.setCellStyle(style);

        cell = row.createCell(1);
        cell.setCellValue("1234");

        sheet.autoSizeColumn(0);

        try {
            FileOutputStream stream = new FileOutputStream(new
File(System.getProperty("user.home"),
                    "Book1.xls"));
            workBook.write(stream);
        } catch (IOException error) {
        }
    }

}

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to