]> source.dussan.org Git - poi.git/commitdiff
Implementation of XSSFRow#{get,set}Height and other methods.\rPatch contributed by...
authorUgo Cei <ugo@apache.org>
Tue, 22 Jan 2008 14:26:10 +0000 (14:26 +0000)
committerUgo Cei <ugo@apache.org>
Tue, 22 Jan 2008 14:26:10 +0000 (14:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@614205 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java

index 9ab157e44f9165372d057d8f3ce384d39214768e..6de47db42112f9b1b2dee98f402c0dbb3a3a24d0 100644 (file)
@@ -124,13 +124,17 @@ public class XSSFRow implements Row {
     }
 
     public short getHeight() {
-        // TODO Auto-generated method stub
-        return 0;
+       if (this.row.getHt() > 0) {
+               return (short) (this.row.getHt() * 20);
+       }
+        return -1;
     }
 
     public float getHeightInPoints() {
-        // TODO Auto-generated method stub
-        return 0;
+       if (this.row.getHt() > 0) {
+               return (short) this.row.getHt();
+       }
+        return -1;
     }
 
     public short getLastCellNum() {
@@ -159,8 +163,7 @@ public class XSSFRow implements Row {
     }
 
     public boolean getZeroHeight() {
-        // TODO Auto-generated method stub
-        return false;
+       return this.row.getHidden();
     }
 
     public void removeCell(Cell cell) {
@@ -177,13 +180,11 @@ public class XSSFRow implements Row {
     }
 
     public void setHeight(short height) {
-        // TODO Auto-generated method stub
-
+       this.row.setHt((double) height / 20);
     }
 
     public void setHeightInPoints(float height) {
-        // TODO Auto-generated method stub
-
+       this.row.setHt((double) height);
     }
 
     public void setRowNum(int rowNum) {
@@ -192,7 +193,7 @@ public class XSSFRow implements Row {
     }
 
     public void setZeroHeight(boolean height) {
-        // TODO Auto-generated method stub
+       this.row.setHidden(height);
 
     }
 
index 8bb75660cc7d9cd586da59fe21612ed2fbcea7eb..9ffa352ebb08857f24eac720f524bd58c12f9aa0 100644 (file)
@@ -65,20 +65,20 @@ public class XSSFSheet implements Sheet {
         CTSelection selection = view.addNewSelection();
         selection.setActiveCell("A1");
         CTSheetFormatPr format = this.worksheet.addNewSheetFormatPr();
-        format.setDefaultColWidth(13.2307692307692);
-        format.setDefaultRowHeight(13);
+        format.setDefaultColWidth(13);
+        format.setDefaultRowHeight(15);
         format.setCustomHeight(true);
         CTCols cols = this.worksheet.addNewCols();
         CTCol col = cols.addNewCol();
         col.setMin(1);
         col.setMax(2);
-        col.setWidth(13.2307692307692);
+        col.setWidth(13);
         col.setCustomWidth(true);
         for (int i = 3 ; i < 5 ; ++i) {
             col = cols.addNewCol();
             col.setMin(i);
             col.setMax(i);
-            col.setWidth(13.2307692307692);
+            col.setWidth(13);
             col.setCustomWidth(true);
         }
         CTHeaderFooter hf = this.worksheet.addNewHeaderFooter();
@@ -180,23 +180,20 @@ public class XSSFSheet implements Sheet {
     }
 
     public short getColumnWidth(short column) {
-        // TODO Auto-generated method stub
-        return 0;
+       // TODO Auto-generated method stub
+       return 0;
     }
 
     public short getDefaultColumnWidth() {
-        // TODO Auto-generated method stub
-        return 0;
+       return (short) this.worksheet.getSheetFormatPr().getDefaultColWidth();
     }
 
     public short getDefaultRowHeight() {
-        // TODO Auto-generated method stub
-        return 0;
+       return (short) (this.worksheet.getSheetFormatPr().getDefaultRowHeight() * 20);
     }
 
     public float getDefaultRowHeightInPoints() {
-        // TODO Auto-generated method stub
-        return 0;
+       return (short) this.worksheet.getSheetFormatPr().getDefaultRowHeight();
     }
 
     public boolean getDialog() {
@@ -440,7 +437,6 @@ public class XSSFSheet implements Sheet {
 
     public void setColumnWidth(short column, short width) {
         // TODO Auto-generated method stub
-
     }
 
     public void setDefaultColumnStyle(short column, CellStyle style) {
@@ -449,17 +445,16 @@ public class XSSFSheet implements Sheet {
     }
 
     public void setDefaultColumnWidth(short width) {
-        // TODO Auto-generated method stub
-
+       this.worksheet.getSheetFormatPr().setDefaultColWidth((double) width);
     }
 
     public void setDefaultRowHeight(short height) {
-        // TODO Auto-generated method stub
+       this.worksheet.getSheetFormatPr().setDefaultRowHeight(height / 20);
 
     }
 
     public void setDefaultRowHeightInPoints(float height) {
-        // TODO Auto-generated method stub
+       this.worksheet.getSheetFormatPr().setDefaultRowHeight(height);
 
     }
 
index 7a70ed5ace4f1bd4158ab4884f50446630fa2c33..571e0f4c779d9bcc903075bfb3af40754b476038 100644 (file)
@@ -141,6 +141,28 @@ public class TestXSSFRow extends TestCase {
        
     }
     
+    public void testGetSetHeight() throws Exception {
+        XSSFRow row = getSampleRow();
+        // I assume that "ht" attribute value is in 'points', please verify that
+        // Test that no rowHeight is set
+        assertEquals((short) -1, row.getHeight());
+        // Set a rowHeight in twips (1/20th of a point) and test the new value
+        row.setHeight((short) 240);
+        assertEquals((short) 240, row.getHeight());
+        assertEquals((float) 12, row.getHeightInPoints());
+        // Set a new rowHeight in points and test the new value
+        row.setHeightInPoints((float) 13);
+        assertEquals((float) 13, row.getHeightInPoints());
+        assertEquals((short) 260, row.getHeight());
+    }
+    
+    public void testGetSetZeroHeight() throws Exception {
+        XSSFRow row = getSampleRow();
+        assertFalse(row.getZeroHeight());
+        row.setZeroHeight(true);
+        assertTrue(row.getZeroHeight());
+    }
+    
     /**
      * Method that returns a row with some sample cells
      * @return row
index aaa30b36112c6104493f6fa22b14d9739ea75f46..f0a9f37aca828b342e156d9aceeb47e0a3bc8345 100644 (file)
@@ -86,8 +86,29 @@ public class TestXSSFSheet extends TestCase {
                Row row2_overwritten_copy = it2.next();
                assertEquals(row2_ovrewritten, row2_overwritten_copy);
                assertEquals(row2_overwritten_copy.getCell((short) 0).getNumericCellValue(), (double) 100);
-               
-               
-               
+       }
+       
+       public void testGetSetDefaultRowHeight() throws Exception {
+               XSSFWorkbook workbook = new XSSFWorkbook();
+               Sheet sheet = workbook.createSheet("Sheet 1");
+               // Test that default height set by the constructor
+               assertEquals((short) 300, sheet.getDefaultRowHeight());
+               assertEquals((float) 15, sheet.getDefaultRowHeightInPoints());
+               // Set a new default row height in twips and test getting the value in points
+               sheet.setDefaultRowHeight((short) 360);
+               assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
+               // Set a new default row height in points and test getting the value in twips
+               sheet.setDefaultRowHeightInPoints((short) 17);
+               assertEquals((short) 340, sheet.getDefaultRowHeight());
+       }
+       
+       public void testGetSetDefaultColumnWidth() throws Exception {
+               XSSFWorkbook workbook = new XSSFWorkbook();
+               Sheet sheet = workbook.createSheet("Sheet 1");
+               // Test that default column width set by the constructor
+               assertEquals((short) 13, sheet.getDefaultColumnWidth());
+               // Set a new default column width and get its value
+               sheet.setDefaultColumnWidth((short) 14);
+               assertEquals((short) 14, sheet.getDefaultColumnWidth());
        }
 }