Bug 43902 - HSSFSheet:autoSizeColumn doesn't consider merged regions
Summary: HSSFSheet:autoSizeColumn doesn't consider merged regions
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2007-11-19 04:14 UTC by Andreas Radauer
Modified: 2008-01-09 03:15 UTC (History)
0 users

This patch resolves 43902 bug (3.59 KB, patch)
2008-01-09 01:45 UTC, Paolo Mottadelli
Details | Diff
Attached document for autoSizeColumn test (81.50 KB, application/vnd.ms-excel)
2008-01-09 01:47 UTC, Paolo Mottadelli

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Radauer 2007-11-19 04:14:07 UTC
The autoSizeColumn method does not consider merged regions:

HSSFWorkbook wb = new HSSFWorkbook();
	    HSSFSheet sheet = wb.createSheet("new sheet");
	    //add two rows with each a cell
	    HSSFRow row = sheet.createRow((short)0);
	    HSSFCell cell = row.createCell((short)0);
	    cell.setCellValue(new HSSFRichTextString("This is a Text"));
	    HSSFRow row2 = sheet.createRow((short)1);
	    HSSFCell cell2 = row2.createCell((short)0);
	    cell2.setCellValue(new HSSFRichTextString("This is a very long 
long long Text"));
	    //create a region over the 2nd row
	    sheet.addMergedRegion(new Region(1,(short)0,1,(short)1));
	    //auto size the Collumns

	    // Write the output to a file
	    FileOutputStream fileOut = new FileOutputStream("workbook.xls");

If you use the autoSizeColumn function in Excel (double click) on the collumn 
heading, the collumn has the size of the first line. If you use the 
auotSizeColumn method of HSSFSheet it has the size of the 2nd.
Comment 1 Yegor Kozlov 2007-11-19 06:07:58 UTC
Thanks for the bug report. I will look into it. 
Looks like Excel does not autosize merged columns, i.e. merged columns should be
skipped in the autoSizeColumn().  

Comment 2 Paolo Mottadelli 2008-01-09 01:45:51 UTC
Created attachment 21362 [details]
This patch resolves 43902 bug

The autoSizeColumn method has to ignore the rows that are part of a merged
region. This is the Excel behavior.
the next attached document has to be saved as:
Comment 3 Paolo Mottadelli 2008-01-09 01:47:33 UTC
Created attachment 21363 [details]
Attached document for autoSizeColumn test

save this attachment as:
Comment 4 Nick Burch 2008-01-09 01:56:03 UTC
Thanks for that patch Paolo, applied to svn