Bugzilla 52626: fixed setting default row height in HSSF and XSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1243240 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2012-02-12 11:14:23 +00:00
parent 7e7bde2595
commit bc48e85daa
6 changed files with 23 additions and 4 deletions

View File

@ -1002,6 +1002,8 @@ public final class InternalSheet {
*/
public void setDefaultRowHeight(short dch) {
defaultrowheight.setRowHeight(dch);
// set the bit that specifies that the default settings for the row height have been changed.
defaultrowheight.setOptionFlags((short)1);
}
/**

View File

@ -197,6 +197,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
public HSSFRow createRow(int rownum)
{
HSSFRow row = new HSSFRow(_workbook, this, rownum);
// new rows inherit default height from the sheet
row.setHeight(getDefaultRowHeight());
addRow(row, true);
return row;

View File

@ -2060,8 +2060,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* @param height default row height in twips (1/20 of a point)
*/
public void setDefaultRowHeight(short height) {
getSheetTypeSheetFormatPr().setDefaultRowHeight((double)height / 20);
setDefaultRowHeightInPoints((float)height / 20);
}
/**
@ -2070,8 +2069,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* @param height default row height measured in point size.
*/
public void setDefaultRowHeightInPoints(float height) {
getSheetTypeSheetFormatPr().setDefaultRowHeight(height);
CTSheetFormatPr pr = getSheetTypeSheetFormatPr();
pr.setDefaultRowHeight(height);
pr.setCustomHeight(true);
}
/**

View File

@ -19,6 +19,7 @@
package org.apache.poi.xssf.streaming;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestRow;
import org.apache.poi.xssf.SXSSFITestDataProvider;
@ -30,4 +31,13 @@ public final class TestSXSSFRow extends BaseTestRow {
public TestSXSSFRow() {
super(SXSSFITestDataProvider.instance);
}
public void testRowBounds() {
baseTestRowBounds(SpreadsheetVersion.EXCEL2007.getLastRowIndex());
}
public void testCellBounds() {
baseTestCellBounds(SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
}
}

View File

@ -292,6 +292,7 @@ public abstract class BaseTestRow extends TestCase {
assertEquals(20*20, row1.getHeight());
Row row2 = sheet.createRow(1);
assertEquals(sheet.getDefaultRowHeight(), row2.getHeight());
row2.setHeight((short)310);
assertEquals(310, row2.getHeight());
assertEquals(310F/20, row2.getHeightInPoints(), 0F);

View File

@ -401,6 +401,10 @@ public abstract class BaseTestSheet extends TestCase {
assertEquals((short) 300, sheet.getDefaultRowHeight());
assertEquals(15.0F, sheet.getDefaultRowHeightInPoints(), 0F);
Row row = sheet.createRow(1);
// new row inherits default height from the sheet
assertEquals(sheet.getDefaultRowHeight(), row.getHeight());
// Set a new default row height in twips and test getting the value in points
sheet.setDefaultRowHeight((short) 360);
assertEquals(18.0f, sheet.getDefaultRowHeightInPoints(), 0F);