poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1717900 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases...
Date Fri, 04 Dec 2015 06:36:28 GMT
Author: onealj
Date: Fri Dec  4 06:36:27 2015
New Revision: 1717900

URL: http://svn.apache.org/viewvc?rev=1717900&view=rev
Log:
bug 58570: add get/setActiveCell to Sheet interface, add Cell.getAddress, 

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Fri Dec  4 06:36:27 2015
@@ -48,6 +48,7 @@ import org.apache.poi.ss.usermodel.Comme
 import org.apache.poi.ss.usermodel.FormulaError;
 import org.apache.poi.ss.usermodel.Hyperlink;
 import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.ss.util.NumberToTextConverter;
@@ -223,18 +224,10 @@ public class HSSFCell implements Cell {
     /**
      * @return the (zero based) index of the row containing this cell
      */
+    @Override
     public int getRowIndex() {
         return _record.getRow();
     }
-    /**
-     * Set the cell's number within the row (0 based).
-     * @param num  short the cell number
-     * @deprecated (Jan 2008) Doesn't update the row's idea of what cell this is, use {@link
HSSFRow#moveCell(HSSFCell, short)} instead
-     */
-    public void setCellNum(short num)
-    {
-        _record.setColumn(num);
-    }
 
     /**
      * Updates the cell record's idea of what
@@ -246,18 +239,21 @@ public class HSSFCell implements Cell {
         _record.setColumn(num);
     }
 
-    /**
-     * @deprecated (Oct 2008) use {@link #getColumnIndex()}
-     */
-    public short getCellNum() {
-        return (short) getColumnIndex();
-    }
-
+    @Override
     public int getColumnIndex() {
         return _record.getColumn() & 0xFFFF;
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CellAddress getAddress() {
+        return new CellAddress(this);
+    }
+    
+
+    /**
      * Set the cells type (numeric, formula or string).
      * If the cell currently contains a value, the value will
      *  be converted to match the new type, if possible.
@@ -950,8 +946,9 @@ public class HSSFCell implements Cell {
     }
 
     /**
-     * Sets this cell as the active cell for the worksheet
+     * {@inheritDoc}
      */
+    @Override
     public void setAsActiveCell()
     {
         int row=_record.getRow();

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java Fri Dec  4 06:36:27 2015
@@ -21,6 +21,7 @@ import java.util.Calendar;
 import java.util.Date;
 
 import org.apache.poi.ss.formula.FormulaParseException;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellRangeAddress;
 
 /**
@@ -349,6 +350,14 @@ public interface Cell {
      */
     void setAsActiveCell();
 
+   /**
+     * Gets the address of this cell
+     *
+     * @return <code>A1</code> style address of this cell
+     * @since 3.14beta2
+     */
+    CellAddress getAddress();
+
     /**
      * Assign a comment to this cell
      *

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java Fri Dec  4 06:36:27 2015
@@ -1118,4 +1118,20 @@ public interface Sheet extends Iterable<
      * @return Hyperlinks for the sheet
      */
     public List<? extends Hyperlink> getHyperlinkList();
+
+    /**
+     * Return location of the active cell, e.g. <code>A1</code>.
+     *
+     * @return the location of the active cell.
+     * @since 3.14beta2
+     */
+    public CellAddress getActiveCell();
+
+    /**
+      * Sets location of the active cell
+      *
+      * @param cellRef the location of the active cell, e.g. <code>A1</code>.
+      * @since 3.14beta2
+      */
+    public void setActiveCell(CellAddress addr);
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Fri Dec  4 06:36:27
2015
@@ -33,6 +33,7 @@ import org.apache.poi.ss.usermodel.Formu
 import org.apache.poi.ss.usermodel.Hyperlink;
 import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.LocaleUtil;
@@ -84,6 +85,14 @@ public class SXSSFCell implements Cell {
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CellAddress getAddress() {
+        return new CellAddress(this);
+    }
+
+    /**
      * Returns the sheet this cell belongs to
      *
      * @return the sheet this cell belongs to
@@ -564,15 +573,12 @@ public class SXSSFCell implements Cell {
     }
 
     /**
-     * Sets this cell as the active cell for the worksheet
+     * {@inheritDoc}
      */
-    @NotImplemented
     @Override
     public void setAsActiveCell()
     {
-        throw new RuntimeException("NotImplemented");
-        //TODO: What needs to be done here? Is there a "the active cell" at the sheet or
even the workbook level?
-        //getRow().setAsActiveCell(this);
+        getSheet().setActiveCell(getAddress());
     }
 
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Fri Dec  4 06:36:27
2015
@@ -1874,4 +1874,20 @@ public class SXSSFSheet implements Sheet
     public int getColumnOutlineLevel(int columnIndex) {
         return _sh.getColumnOutlineLevel(columnIndex);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CellAddress getActiveCell() {
+        return _sh.getActiveCell();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setActiveCell(CellAddress addr) {
+        _sh.setActiveCell(addr);
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Fri Dec  4 06:36:27
2015
@@ -586,12 +586,20 @@ public final class XSSFCell implements C
     public String getReference() {
         String ref = _cell.getR();
         if(ref == null) {
-            return new CellAddress(this).formatAsString();
+            return getAddress().formatAsString();
         }
         return ref;
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CellAddress getAddress() {
+        return new CellAddress(this);
+    }
+
+    /**
      * Return the cell's style.
      *
      * @return the cell's style.</code>
@@ -816,11 +824,11 @@ public final class XSSFCell implements C
     }
 
     /**
-     * Sets this cell as the active cell for the worksheet.
+     * {@inheritDoc}
      */
     @Override
     public void setAsActiveCell() {
-        getSheet().setActiveCell(getReference());
+        getSheet().setActiveCell(getAddress());
     }
 
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Fri Dec  4 06:36:27
2015
@@ -3110,14 +3110,20 @@ public class XSSFSheet extends POIXMLDoc
      *
      * @return the location of the active cell.
      */
-    public String getActiveCell() {
-        return getSheetTypeSelection().getActiveCell();
+    @Override
+    public CellAddress getActiveCell() {
+        String address = getSheetTypeSelection().getActiveCell();
+        if (address == null) {
+            return null;
+        }
+        return new CellAddress(address);
     }
 
     /**
      * Sets location of the active cell
      *
      * @param cellRef the location of the active cell, e.g. <code>A1</code>..
+     * @deprecated 3.14beta2 (circa 2015-12-05). Use {@link #setActiveCell(CellAddress)}
instead.
      */
     public void setActiveCell(String cellRef) {
         CTSelection ctsel = getSheetTypeSelection();
@@ -3126,6 +3132,17 @@ public class XSSFSheet extends POIXMLDoc
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setActiveCell(CellAddress address) {
+        String ref = address.formatAsString();
+        CTSelection ctsel = getSheetTypeSelection();
+        ctsel.setActiveCell(ref);
+        ctsel.setSqref(Arrays.asList(ref));
+    }
+
+    /**
      * Does this sheet have any comments on it? We need to know,
      *  so we can decide about writing it to disk or not
      */

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Dec
 4 06:36:27 2015
@@ -50,6 +50,7 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.AreaReference;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.ss.util.CellUtil;
@@ -235,9 +236,10 @@ public final class TestXSSFSheet extends
     public void getActiveCell() throws IOException {
         XSSFWorkbook workbook = new XSSFWorkbook();
         XSSFSheet sheet = workbook.createSheet();
-        sheet.setActiveCell("R5");
+        CellAddress R5 = new CellAddress("R5");
+        sheet.setActiveCell(R5);
 
-        assertEquals("R5", sheet.getActiveCell());
+        assertEquals(R5, sheet.getActiveCell());
         workbook.close();
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Fri Dec  4 06:36:27
2015
@@ -936,4 +936,22 @@ public abstract class BaseTestCell {
         }
         wb.close();
     }
+
+    /**
+     * Tests that the setAsActiveCell and getActiveCell function pairs work together
+     */
+    @Test
+    public void setAsActiveCell() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet();
+        Row row = sheet.createRow(0);
+        Cell A1 = row.createCell(0);
+        Cell B1 = row.createCell(1);
+
+        A1.setAsActiveCell();
+        assertEquals(A1.getAddress(), sheet.getActiveCell());
+
+        B1.setAsActiveCell();
+        assertEquals(B1.getAddress(), sheet.getActiveCell());
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1717900&r1=1717899&r2=1717900&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Fri Dec  4 06:36:27
2015
@@ -1152,4 +1152,29 @@ public abstract class BaseTestSheet {
         assertTrue(sheet.getMergedRegions().isEmpty());
         wb.close();
     }
+
+    /**
+     * Tests that the setAsActiveCell and getActiveCell function pairs work together
+     */
+    @Test
+    public void setActiveCell() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
+        CellAddress B42 = new CellAddress("B42");
+        
+        // active cell behavior is undefined if not set.
+        // HSSFSheet defaults to A1 active cell, while XSSFSheet defaults to null.
+        if (sheet.getActiveCell() != null && !sheet.getActiveCell().equals(CellAddress.A1))
{
+            fail("If not set, active cell should default to null or A1");
+        }
+
+        sheet.setActiveCell(B42);
+
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+
+        assertEquals(B42, sheet.getActiveCell());
+
+        wb1.close();
+        wb2.close();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message