Lines 32-37
Link Here
|
32 |
import org.apache.poi.hssf.record.WSBoolRecord; |
32 |
import org.apache.poi.hssf.record.WSBoolRecord; |
33 |
import org.apache.poi.hssf.record.WindowTwoRecord; |
33 |
import org.apache.poi.hssf.record.WindowTwoRecord; |
34 |
import org.apache.poi.hssf.util.Region; |
34 |
import org.apache.poi.hssf.util.Region; |
|
|
35 |
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
35 |
import org.apache.poi.util.TempFile; |
36 |
import org.apache.poi.util.TempFile; |
36 |
|
37 |
|
37 |
/** |
38 |
/** |
Lines 615-620
Link Here
|
615 |
assertTrue("No Exceptions while reading file", true); |
616 |
assertTrue("No Exceptions while reading file", true); |
616 |
|
617 |
|
617 |
} |
618 |
} |
|
|
619 |
|
620 |
public void testAutoSizeColumn() throws Exception { |
621 |
String filename = System.getProperty("HSSF.testdata.path"); |
622 |
filename = filename + "/43902.xls"; |
623 |
String sheetName = "my sheet"; |
624 |
FileInputStream is = new FileInputStream(filename); |
625 |
POIFSFileSystem fs = new POIFSFileSystem(is); |
626 |
HSSFWorkbook wb = new HSSFWorkbook(fs); |
627 |
HSSFSheet sheet = wb.getSheet(sheetName); |
628 |
|
629 |
// autoSize the first column and check its size before the merged region (1,0,1,1) is set: |
630 |
// it has to be based on the 2nd row width |
631 |
sheet.autoSizeColumn((short)0); |
632 |
assertEquals("Column autosized with only one row: wrong width", (short)7169, sheet.getColumnWidth((short)0)); |
633 |
|
634 |
//create a region over the 2nd row and auto size the first column |
635 |
sheet.addMergedRegion(new Region(1,(short)0,1,(short)1)); |
636 |
sheet.autoSizeColumn((short)0); |
637 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
638 |
wb.write(out); |
639 |
out.close(); |
640 |
|
641 |
// check that the autoSized column width has ignored the 2nd row |
642 |
// because it is included in a merged region (Excel like behavior) |
643 |
HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); |
644 |
HSSFSheet sheet2 = wb2.getSheet(sheetName); |
645 |
assertEquals((short)3024, sheet2.getColumnWidth((short)0)); |
646 |
|
647 |
// remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width |
648 |
sheet2.removeMergedRegion(1); |
649 |
sheet2.autoSizeColumn((short)0); |
650 |
out = new ByteArrayOutputStream(); |
651 |
wb2.write(out); |
652 |
out.close(); |
653 |
HSSFWorkbook wb3 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); |
654 |
HSSFSheet sheet3 = wb3.getSheet(sheetName); |
655 |
assertEquals((short)7169, sheet3.getColumnWidth((short)0)); |
656 |
} |
618 |
|
657 |
|
619 |
public static void main(java.lang.String[] args) { |
658 |
public static void main(java.lang.String[] args) { |
620 |
junit.textui.TestRunner.run(TestHSSFSheet.class); |
659 |
junit.textui.TestRunner.run(TestHSSFSheet.class); |