]> source.dussan.org Git - poi.git/commitdiff
Added getters to parent objects: HSSFSheet.getWorkbook(), HSSFRow.getSheet() and...
authorYegor Kozlov <yegor@apache.org>
Wed, 17 Dec 2008 18:55:07 +0000 (18:55 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 17 Dec 2008 18:55:07 +0000 (18:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@727469 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java

index b1e0956750dc6000799b9e80c5bb75723d2ab442..b04cc4a7966a810965eea5fd00bc6ab15052ac81 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Added getters to parent objects: HSSFSheet.getWorkbook(), HSSFRow.getSheet() and HSSFCell.getRow()</action>
            <action dev="POI-DEVELOPERS" type="fix">46385 - (also patch 46362) fix serialization of StyleRecord with unicode name</action>
            <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
index cc08e74ee14365095a39280bf9e479d4361f38c5..61ae91cd4d3c67fc0e87b11e4df61a2a8ea33061 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Added getters to parent objects: HSSFSheet.getWorkbook(), HSSFRow.getSheet() and HSSFCell.getRow()</action>
            <action dev="POI-DEVELOPERS" type="fix">46385 - (also patch 46362) fix serialization of StyleRecord with unicode name</action>
            <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
index f97be8f8e48848fdc396760a1b82c4bb2423db07..838a0db95e4d48d958b3dd0b4e4b9613e389cdd2 100644 (file)
@@ -127,10 +127,26 @@ public class HSSFCell implements Cell {
         short xfindex = sheet.getSheet().getXFIndexForColAt(col);
         setCellType(CELL_TYPE_BLANK, false, row, col,xfindex);
     }
+
+    /**
+     * Returns the HSSFSheet this cell belongs to
+     *
+     * @return the HSSFSheet that owns this cell
+     */
     public HSSFSheet getSheet() {
         return sheet;
     }
 
+    /**
+     * Returns the HSSFRow this cell belongs to
+     *
+     * @return the HSSFRow that owns this cell
+     */
+    public HSSFRow getRow() {
+        int rowIndex = getRowIndex();
+        return sheet.getRow(rowIndex);
+    }
+
     /**
      * Creates new Cell - Should only be called by HSSFRow.  This creates a cell
      * from scratch.
index c6f9dca5360ccb53708bb9fca5083a4711b5bf04..ebd83a86b3fc1f6072aa8d6a86e02898b568ec67 100644 (file)
@@ -233,6 +233,16 @@ public final class HSSFRow implements Comparable, Row {
         return rowNum;
     }
     
+    /**
+     * Returns the HSSFSheet this row belongs to
+     *
+     * @return the HSSFSheet that owns this row
+     */
+    public HSSFSheet getSheet()
+    {
+        return sheet;
+    }
+
     /**
      * Returns the rows outline level. Increased as you
      *  put it into more groups (outlines), reduced as
index fe337b0f90278515b4e097402f44920e3f0fce46..08abbb61f6afb06f941d9576368ffd883aef3c8b 100644 (file)
@@ -128,6 +128,14 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
       return new HSSFSheet(workbook, sheet.cloneSheet());
     }
 
+    /**
+     * Return the parent workbook
+     *
+     * @return the parent workbook
+     */
+    public HSSFWorkbook getWorkbook(){
+        return workbook;    
+    }
 
     /**
      * used internally to set the properties given a Sheet object
index 3110d849c6cdfcade0f57734348556e7825caffe..8816025a4f6c6ac8e2bd3e600891b896d239f912 100644 (file)
@@ -98,6 +98,13 @@ public interface Cell {
      */
     Sheet getSheet();
 
+    /**
+     * Returns the Row this cell belongs to
+     *
+     * @return the Row that owns this cell
+     */
+     Row getRow();
+
     /**
      * Set the cells type (numeric, formula or string)
      *
index f29a437c99da427a0a1587820329a51b53d1591a..a1db2fb3675e5863239030ed6e5a39b49c900b14 100644 (file)
@@ -183,6 +183,13 @@ public interface Row extends Iterable<Cell> {
      */
     Iterator<Cell> cellIterator();
 
+    /**
+     * Returns the Sheet this row belongs to
+     *
+     * @return the Sheet that owns this row
+     */
+    Sheet getSheet();
+
     /**
      * Used to specify the different possible policies
      *  if for the case of null and blank cells
index 7e7645995b8fb6175418d16b92e2fcce9571bac1..9650db2009171d6425aa2f4d673e6226a7d637c3 100644 (file)
@@ -712,4 +712,11 @@ public interface Sheet extends Iterable<Row> {
      */
     Drawing createDrawingPatriarch();
 
+
+    /**
+     * Return the parent workbook
+     *
+     * @return the parent workbook
+     */
+    Workbook getWorkbook();
 }
index 6ce69eaecc9cae075ee15732a5b91945f99d0a79..cfcb3670e2dfd59ca288e7c65b2b3af4da209fbf 100644 (file)
@@ -545,4 +545,30 @@ public final class TestWorkbook extends TestCase {
 
         assertTrue("file exists",file.exists());
     }
+
+    public void testParentReferences(){
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet();
+        assertSame(workbook, sheet.getWorkbook());
+
+        HSSFRow row = sheet.createRow(0);
+        assertSame(sheet, row.getSheet());
+
+        HSSFCell cell = row.createCell(1);
+        assertSame(sheet, cell.getSheet());
+        assertSame(row, cell.getRow());
+
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+        sheet = workbook.getSheetAt(0);
+        assertSame(workbook, sheet.getWorkbook());
+
+        row = sheet.getRow(0);
+        assertSame(sheet, row.getSheet());
+
+        cell = row.getCell(1);
+        assertSame(sheet, cell.getSheet());
+        assertSame(row, cell.getRow());
+
+
+    }
 }