Bug 55105 - autoSizeColumn not working properly for data type values
Summary: autoSizeColumn not working properly for data type values
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-17 08:17 UTC by uogra
Modified: 2014-01-06 18:43 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description uogra 2013-06-17 08:17:17 UTC
Workbook wb = new XSSFWorkbook();
		CreationHelper createHelper = wb.getCreationHelper();
		Sheet sheet = wb.createSheet();
		Row row = sheet.createRow(0);
		CellStyle cellStyle = wb.createCellStyle();
		cellStyle.setDataFormat((short) 14);
		Cell cell = row.createCell(0);
		cell.setCellType(Cell.CELL_TYPE_NUMERIC);
		cell.setCellValue(new Date("13-jan-2013"));
		cell.setCellStyle(cellStyle);
		
		cell = row.createCell(1);
		cell.setCellType(Cell.CELL_TYPE_STRING);
		cell.setCellValue("13-jan-2013");
		cell.setCellStyle(cellStyle);
		 sheet.autoSizeColumn(0, false);
		 sheet.autoSizeColumn(1, false);

In the above example I am adding 2 cells to different columns. One has string type value and other has date type value. Value is same "13-jan-2013"

When I call autosizecolumn in both columns, first ccolumn doesnt exapnd to fit in the data whereas 2nd column expands properly.

I noticed this thing :
Internally autosizecolumn  is using SheetUtil.getColumnWidth to get current max width of column. It is returning a value of 8 something.
Previously autosizecolumn   was using ColumnHelper.getColumnWidth method and used to return 12 for same data ("13-jan-2013"). This is why in previous version  autosizecolumn   was working properly for even date type fields
Comment 1 Nick Burch 2013-06-18 22:30:25 UTC
Do you have the correct fonts installed on your system and available to Java? POI uses the fonts to work out how wide columns are, and it can't get it right if Java doesn't have the fonts you're using available. Are they all correctly there?
Comment 2 uogra 2013-06-19 12:33:33 UTC
The same code if I run with 3.7 version runs fine and it properly autosizes the column
But in 3.9 version it doesnt and internal implemented method returns lesser value of max column width.
Both examples I have run on same system. Plus we have also run on other testing systems
So I don't think fonts are the issue
Comment 3 uogra 2014-01-06 12:28:41 UTC
Any progress on this bug?
Comment 4 Bodo Wippermann 2014-01-06 18:43:16 UTC
i don't see a bug here.
you are formatting the Date Cell with format id 14 which seems to be locale dependent.

i tried this snippet

XSSFDataFormat format = wb.createDataFormat();
cellStyle.setDataFormat(format.getFormat("dd-MMM-yyyy"));

and both Colums are properly sized.