]> source.dussan.org Git - poi.git/commitdiff
XSSFSheet addMergedRegion + Region class moved to org.apache.poi.ss.util.Region ...
authorPaolo Mottadelli <paolo@apache.org>
Sun, 6 Apr 2008 20:34:00 +0000 (20:34 +0000)
committerPaolo Mottadelli <paolo@apache.org>
Sun, 6 Apr 2008 20:34:00 +0000 (20:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645303 13f79535-47bb-0310-9956-ffa450edef68

21 files changed:
src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
src/java/org/apache/poi/hssf/dev/HSSF.java
src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
src/java/org/apache/poi/hssf/record/cf/CellRange.java
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/hssf/util/Region.java [deleted file]
src/java/org/apache/poi/ss/util/Region.java [new file with mode: 0644]
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java [deleted file]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
src/testcases/org/apache/poi/ss/util/TestCellReference.java [new file with mode: 0644]
src/testcases/org/apache/poi/ss/util/TestRegion.java [new file with mode: 0644]

index f587f022fe34dfe533d284933b0b82154a00419a..ea525149c790ed707b1811b413ecfda8d0bb66cb 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 import org.apache.commons.lang.exception.NestableException;
 
index c44d81617f681282e87a7fdf46220d4dfbdc7c18..fa66d76f0a013fa14be0e96bc01ce5d6969680e1 100644 (file)
@@ -20,7 +20,7 @@
 package org.apache.poi.hssf.usermodel.examples;
 
 import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 import java.io.IOException;
 import java.io.FileOutputStream;
index 7dddca966a3afdd368e53f7c042f032dd7aa2211..4302357c47cf095c7b460460fe442deac2425af0 100644 (file)
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.hssf.util.*;
 
index d74d54ab1732d6c82239d8e5db751d252846346c..224f5e5c193aea4b002c98d8c6bd19391f27be01 100644 (file)
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.hssf.record.cf.CellRange;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.LittleEndian;
 
 /**
index 81154ebb22c5a43893bb85c1c5d9b2ba956259af..d91269ed342eee9832ef3466f0f63c2c55ac550b 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
index f45b79b003a88c86a513334731ea2c8f3863ae98..41cb4a2a2952a8815da7a0e11013170a16514f00 100644 (file)
@@ -21,7 +21,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 /**
  * 
index d9e470a68cdd9dbc682d3ad8486d65732d27dce1..6a08c4b3041267915396c25ca5346accbdb6c521 100644 (file)
@@ -21,7 +21,7 @@ import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.cf.CellRange;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 /**
  * HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting. 
index 4aad1e1b18f7c1e28f4a9b4ca1c2cb5203696491..ca0c126f422c6d60a51b84a328934c8deea696de 100644 (file)
@@ -55,9 +55,9 @@ import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.util.HSSFCellRangeAddress;
 import org.apache.poi.hssf.util.HSSFDataValidation;
 import org.apache.poi.hssf.util.PaneInformation;
-import org.apache.poi.hssf.util.Region;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
diff --git a/src/java/org/apache/poi/hssf/util/Region.java b/src/java/org/apache/poi/hssf/util/Region.java
deleted file mode 100644 (file)
index 67d52eb..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-
-package org.apache.poi.hssf.util;
-
-import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion;
-
-/**
- * Represents a from/to row/col square.  This is a object primitive
- * that can be used to represent row,col - row,col just as one would use String
- * to represent a string of characters.  Its really only useful for HSSF though.
- *
- * @author  Andrew C. Oliver acoliver at apache dot org
- */
-
-public class Region
-    implements Comparable
-{
-    private int   rowFrom;
-    private short colFrom;
-    private int   rowTo;
-    private short colTo;
-
-    /**
-     * Creates a new instance of Region (0,0 - 0,0)
-     */
-
-    public Region()
-    {
-    }
-
-    public Region(int rowFrom, short colFrom, int rowTo, short colTo)
-    {
-        this.rowFrom = rowFrom;
-        this.rowTo   = rowTo;
-        this.colFrom = colFrom;
-        this.colTo   = colTo;
-    }
-
-    /**
-     * special constructor (I know this is bad but it is so wrong that its right
-     * okay) that makes a region from a mergedcells's region subrecord.
-     */
-
-    public Region(MergedRegion region)
-    {
-        this(region.row_from, region.col_from, region.row_to, region.col_to);
-    }
-
-    /**
-     * get the upper left hand corner column number
-     *
-     * @return column number for the upper left hand corner
-     */
-
-    public short getColumnFrom()
-    {
-        return colFrom;
-    }
-
-    /**
-     * get the upper left hand corner row number
-     *
-     * @return row number for the upper left hand corner
-     */
-
-    public int getRowFrom()
-    {
-        return rowFrom;
-    }
-
-    /**
-     * get the lower right hand corner column number
-     *
-     * @return column number for the lower right hand corner
-     */
-
-    public short getColumnTo()
-    {
-        return colTo;
-    }
-
-    /**
-     * get the lower right hand corner row number
-     *
-     * @return row number for the lower right hand corner
-     */
-
-    public int getRowTo()
-    {
-        return rowTo;
-    }
-
-    /**
-     * set the upper left hand corner column number
-     *
-     * @param colFrom  column number for the upper left hand corner
-     */
-
-    public void setColumnFrom(short colFrom)
-    {
-        this.colFrom = colFrom;
-    }
-
-    /**
-     * set the upper left hand corner row number
-     *
-     * @param rowFrom  row number for the upper left hand corner
-     */
-
-    public void setRowFrom(int rowFrom)
-    {
-        this.rowFrom = rowFrom;
-    }
-
-    /**
-     * set the lower right hand corner column number
-     *
-     * @param colTo  column number for the lower right hand corner
-     */
-
-    public void setColumnTo(short colTo)
-    {
-        this.colTo = colTo;
-    }
-
-    /**
-     * get the lower right hand corner row number
-     *
-     * @param rowTo  row number for the lower right hand corner
-     */
-
-    public void setRowTo(int rowTo)
-    {
-        this.rowTo = rowTo;
-    }
-
-    /**
-     * Answers: "is the row/column inside this range?"
-     *
-     * @return <code>true</code> if the cell is in the range and
-     * <code>false</code> if it is not
-     */
-
-    public boolean contains(int row, short col)
-    {
-        if ((this.rowFrom <= row) && (this.rowTo >= row)
-                && (this.colFrom <= col) && (this.colTo >= col))
-        {
-
-//                System.out.println("Region ("+rowFrom+","+colFrom+","+rowTo+","+ 
-//                                   colTo+") does contain "+row+","+col);
-            return true;
-        }
-        return false;
-    }
-
-    public boolean equals(Region r)
-    {
-        return (compareTo(r) == 0);
-    }
-
-    /**
-     * Compares that the given region is the same less than or greater than this
-     * region.  If any regional coordiant passed in is less than this regions
-     * coordinants then a positive integer is returned.  Otherwise a negative
-     * integer is returned.
-     *
-     * @param r  region
-     * @see #compareTo(Object)
-     */
-
-    public int compareTo(Region r)
-    {
-        if ((this.getRowFrom() == r.getRowFrom())
-                && (this.getColumnFrom() == r.getColumnFrom())
-                && (this.getRowTo() == r.getRowTo())
-                && (this.getColumnTo() == r.getColumnTo()))
-        {
-            return 0;
-        }
-        if ((this.getRowFrom() < r.getRowFrom())
-                || (this.getColumnFrom() < r.getColumnFrom())
-                || (this.getRowTo() < r.getRowTo())
-                || (this.getColumnTo() < r.getColumnTo()))
-        {
-            return 1;
-        }
-        return -1;
-    }
-
-    public int compareTo(Object o)
-    {
-        return compareTo(( Region ) o);
-    }
-
-    /**
-     * @return the area contained by this region (number of cells)
-     */
-
-    public int getArea()
-    {
-        return ((1 + (getRowTo() - getRowFrom()))
-                * (1 + (getColumnTo() - getColumnFrom())));
-    }
-}
diff --git a/src/java/org/apache/poi/ss/util/Region.java b/src/java/org/apache/poi/ss/util/Region.java
new file mode 100644 (file)
index 0000000..e44026c
--- /dev/null
@@ -0,0 +1,231 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+
+package org.apache.poi.ss.util;
+
+import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion;
+
+/**
+ * Represents a from/to row/col square.  This is a object primitive
+ * that can be used to represent row,col - row,col just as one would use String
+ * to represent a string of characters.  Its really only useful for HSSF though.
+ *
+ * @author  Andrew C. Oliver acoliver at apache dot org
+ */
+
+public class Region
+    implements Comparable
+{
+    private int   rowFrom;
+    private short colFrom;
+    private int   rowTo;
+    private short colTo;
+
+    /**
+     * Creates a new instance of Region (0,0 - 0,0)
+     */
+
+    public Region()
+    {
+    }
+
+    public Region(int rowFrom, short colFrom, int rowTo, short colTo)
+    {
+        this.rowFrom = rowFrom;
+        this.rowTo   = rowTo;
+        this.colFrom = colFrom;
+        this.colTo   = colTo;
+    }
+
+    /**
+     * special constructor (I know this is bad but it is so wrong that its right
+     * okay) that makes a region from a mergedcells's region subrecord.
+     */
+
+    public Region(MergedRegion region)
+    {
+        this(region.row_from, region.col_from, region.row_to, region.col_to);
+    }
+
+    /**
+     * get the upper left hand corner column number
+     *
+     * @return column number for the upper left hand corner
+     */
+
+    public short getColumnFrom()
+    {
+        return colFrom;
+    }
+
+    /**
+     * get the upper left hand corner row number
+     *
+     * @return row number for the upper left hand corner
+     */
+
+    public int getRowFrom()
+    {
+        return rowFrom;
+    }
+
+    /**
+     * get the lower right hand corner column number
+     *
+     * @return column number for the lower right hand corner
+     */
+
+    public short getColumnTo()
+    {
+        return colTo;
+    }
+
+    /**
+     * get the lower right hand corner row number
+     *
+     * @return row number for the lower right hand corner
+     */
+
+    public int getRowTo()
+    {
+        return rowTo;
+    }
+
+    /**
+     * set the upper left hand corner column number
+     *
+     * @param colFrom  column number for the upper left hand corner
+     */
+
+    public void setColumnFrom(short colFrom)
+    {
+        this.colFrom = colFrom;
+    }
+
+    /**
+     * set the upper left hand corner row number
+     *
+     * @param rowFrom  row number for the upper left hand corner
+     */
+
+    public void setRowFrom(int rowFrom)
+    {
+        this.rowFrom = rowFrom;
+    }
+
+    /**
+     * set the lower right hand corner column number
+     *
+     * @param colTo  column number for the lower right hand corner
+     */
+
+    public void setColumnTo(short colTo)
+    {
+        this.colTo = colTo;
+    }
+
+    /**
+     * get the lower right hand corner row number
+     *
+     * @param rowTo  row number for the lower right hand corner
+     */
+
+    public void setRowTo(int rowTo)
+    {
+        this.rowTo = rowTo;
+    }
+
+    /**
+     * Answers: "is the row/column inside this range?"
+     *
+     * @return <code>true</code> if the cell is in the range and
+     * <code>false</code> if it is not
+     */
+
+    public boolean contains(int row, short col)
+    {
+        if ((this.rowFrom <= row) && (this.rowTo >= row)
+                && (this.colFrom <= col) && (this.colTo >= col))
+        {
+
+//                System.out.println("Region ("+rowFrom+","+colFrom+","+rowTo+","+ 
+//                                   colTo+") does contain "+row+","+col);
+            return true;
+        }
+        return false;
+    }
+
+    public boolean equals(Region r)
+    {
+        return (compareTo(r) == 0);
+    }
+
+    /**
+     * Compares that the given region is the same less than or greater than this
+     * region.  If any regional coordiant passed in is less than this regions
+     * coordinants then a positive integer is returned.  Otherwise a negative
+     * integer is returned.
+     *
+     * @param r  region
+     * @see #compareTo(Object)
+     */
+
+    public int compareTo(Region r)
+    {
+        if ((this.getRowFrom() == r.getRowFrom())
+                && (this.getColumnFrom() == r.getColumnFrom())
+                && (this.getRowTo() == r.getRowTo())
+                && (this.getColumnTo() == r.getColumnTo()))
+        {
+            return 0;
+        }
+        if ((this.getRowFrom() < r.getRowFrom())
+                || (this.getColumnFrom() < r.getColumnFrom())
+                || (this.getRowTo() < r.getRowTo())
+                || (this.getColumnTo() < r.getColumnTo()))
+        {
+            return 1;
+        }
+        return -1;
+    }
+
+    public int compareTo(Object o)
+    {
+        return compareTo(( Region ) o);
+    }
+
+    /**
+     * @return the area contained by this region (number of cells)
+     */
+
+    public int getArea()
+    {
+        return ((1 + (getRowTo() - getRowFrom()))
+                * (1 + (getColumnTo() - getColumnFrom())));
+    }
+    
+    /**
+     * @return the string reference for this region
+     */
+    public String getRegionRef() {
+       CellReference cellRefFrom = new CellReference(rowFrom, colFrom);
+       CellReference cellRefTo = new CellReference(rowTo, colTo);
+       String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString();
+               return ref;
+    }
+}
index fe533b2841eab792831b2258e4e8ef4e9f6f026f..e9fd943ba8c4ccca3a0db3e42225a48b75801afb 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.poi.ss.usermodel;
 import java.util.Iterator;
 
 import org.apache.poi.hssf.util.PaneInformation;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 public interface Sheet extends Iterable<Row> {
 
index d6106ff20e7de21ba45baaf5fbfd6a42017eefff..50ae19b896a922909942260254d84cb2b13a09af 100644 (file)
@@ -25,7 +25,6 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.poi.hssf.util.PaneInformation;
-import org.apache.poi.hssf.util.Region;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Comment;
 import org.apache.poi.ss.usermodel.CommentsSource;
@@ -37,6 +36,7 @@ import org.apache.poi.ss.usermodel.PrintSetup;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.apache.xmlbeans.XmlOptions;
@@ -48,6 +48,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
@@ -72,6 +74,7 @@ public class XSSFSheet implements Sheet {
     protected ColumnHelper columnHelper;
     protected XSSFWorkbook workbook;
     protected CommentsSource sheetComments;
+    protected CTMergeCells ctMergeCells;
 
     public static final short LeftMargin = 0;
     public static final short RightMargin = 1;
@@ -189,10 +192,18 @@ public class XSSFSheet implements Sheet {
     }
     
     public int addMergedRegion(Region region) {
-        // TODO Auto-generated method stub
-        return 0;
+       addNewMergeCell(region);
+       return ctMergeCells.sizeOfMergeCellArray();
     }
 
+    private void addNewMergeCell(Region region) {
+       if (ctMergeCells == null) {
+               ctMergeCells = worksheet.addNewMergeCells();
+       }
+       CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
+       ctMergeCell.setRef(region.getRegionRef());
+       }
+
     public void autoSizeColumn(short column) {
        columnHelper.setColBestFit(column, true);
     }
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java b/src/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java
deleted file mode 100644 (file)
index 79a1c37..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.xssf.util;
-
-import org.apache.poi.ss.util.CellReference;
-
-import junit.framework.TestCase;
-
-
-/**
- * Tests that the common CellReference works as we need it to
- */
-public class TestCellReference extends TestCase {
-       
-       public void testGetCellRefParts() {
-               CellReference cellReference;
-               String[] parts;
-               
-               String cellRef = "A1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(0, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("1", parts[1]);
-               assertEquals("A", parts[2]);
-
-               cellRef = "AA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("1", parts[1]);
-               assertEquals("AA", parts[2]);
-
-               cellRef = "AA100";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("100", parts[1]);
-               assertEquals("AA", parts[2]);
-
-               cellRef = "AAA300";
-               cellReference = new CellReference(cellRef);
-               assertEquals(702, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("300", parts[1]);
-               assertEquals("AAA", parts[2]);
-
-               cellRef = "ZZ100521";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26*26+25, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("100521", parts[1]);
-               assertEquals("ZZ", parts[2]);
-
-               cellRef = "ZYX987";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26*26*26 + 25*26 + 24 - 1, cellReference.getCol());
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("987", parts[1]);
-               assertEquals("ZYX", parts[2]);
-
-               cellRef = "AABC10065";
-               cellReference = new CellReference(cellRef);
-               parts = cellReference.getCellRefParts();
-               assertNotNull(parts);
-               assertEquals(null, parts[0]);
-               assertEquals("10065", parts[1]);
-               assertEquals("AABC", parts[2]);
-       }
-       
-       public void testGetColNumFromRef() {
-               String cellRef = "A1";
-               CellReference cellReference = new CellReference(cellRef);
-               assertEquals(0, cellReference.getCol());
-
-               cellRef = "AA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26, cellReference.getCol());
-
-               cellRef = "AB1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(27, cellReference.getCol());
-
-               cellRef = "BA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26+26, cellReference.getCol());
-               
-               cellRef = "CA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26+26+26, cellReference.getCol());
-               
-               cellRef = "ZA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26*26, cellReference.getCol());
-               
-               cellRef = "ZZ1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26*26+25, cellReference.getCol());
-               
-               cellRef = "AAA1";
-               cellReference = new CellReference(cellRef);
-               assertEquals(26*26+26, cellReference.getCol());
-               
-               
-               cellRef = "A1100";
-               cellReference = new CellReference(cellRef);
-               assertEquals(0, cellReference.getCol());
-
-               cellRef = "BC15";
-               cellReference = new CellReference(cellRef);
-               assertEquals(54, cellReference.getCol());
-       }
-       
-       public void testGetRowNumFromRef() {
-               String cellRef = "A1";
-               CellReference cellReference = new CellReference(cellRef);
-               assertEquals(0, cellReference.getRow());
-
-               cellRef = "A12";
-               cellReference = new CellReference(cellRef);
-               assertEquals(11, cellReference.getRow());
-
-               cellRef = "AS121";
-               cellReference = new CellReference(cellRef);
-               assertEquals(120, cellReference.getRow());
-       }
-       
-       public void testConvertNumToColString() {
-               short col = 702;
-               String collRef = new CellReference(0, col).formatAsString();
-               assertEquals("AAA1", collRef);
-
-               short col2 = 0;
-               String collRef2 = new CellReference(0, col2).formatAsString();
-               assertEquals("A1", collRef2);
-               
-               short col3 = 27;
-               String collRef3 = new CellReference(0, col3).formatAsString();
-               assertEquals("AB1", collRef3);
-               
-               short col4 = 2080;
-               String collRef4 = new CellReference(0, col4).formatAsString();
-               assertEquals("CBA1", collRef4);
-       }
-}
index f05c1d1157d23e98b12204798e760e954f54d94a..119556c2250427b9f9d3a37d5b117531717c473c 100644 (file)
@@ -20,7 +20,8 @@
 package org.apache.poi.hssf.usermodel;
 
 import junit.framework.TestCase;
-import org.apache.poi.hssf.util.Region;
+
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.TempFile;
 
 import java.io.*;
index a663602ed3230f12aef7a7a545846bb1769053c1..6a0b15158126b6b3263e2ac50ded004eb27a32d8 100644 (file)
@@ -20,7 +20,8 @@
 package org.apache.poi.hssf.usermodel;
 
 import junit.framework.TestCase;
-import org.apache.poi.hssf.util.Region;
+
+import org.apache.poi.ss.util.Region;
 
 /**
  * Test the ability to clone a sheet. 
index 34885e7a21d88ec843ba926776cdf4006099fe74..2c28edf3ac6e529d7da72ea20143fb9118acd30f 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.util.*;
+import org.apache.poi.ss.util.Region;
 
 import java.io.*;
 import java.util.*;
index 5dcc61aa4116773d4eed2c7e683115b1a5b6a8d9..d03a3a40715cf124ffcf2600305c7db4b6c8e602 100644 (file)
@@ -21,7 +21,7 @@ import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 /**
  * 
  * @author Dmitriy Kumshayev
index 13eafa4fd89b6bf0b7495e55f15baad5ef45aff6..f3283677b9183f6b2509770311c9087a145132c8 100644 (file)
@@ -35,8 +35,8 @@ import org.apache.poi.hssf.record.SCLRecord;
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
-import org.apache.poi.hssf.util.Region;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.TempFile;
 
 /**
index efe726a6a564629ec8b7d9e854c4365e58744711..bf6953e78589f3bacc39b5a0532beea0b403f30f 100644 (file)
@@ -25,8 +25,8 @@ import org.apache.poi.hssf.record.BackupRecord;
 import org.apache.poi.hssf.record.LabelSSTRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
-import org.apache.poi.hssf.util.Region;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.TempFile;
 
 import java.io.File;
diff --git a/src/testcases/org/apache/poi/ss/util/TestCellReference.java b/src/testcases/org/apache/poi/ss/util/TestCellReference.java
new file mode 100644 (file)
index 0000000..f13b221
--- /dev/null
@@ -0,0 +1,171 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.util;
+
+import org.apache.poi.ss.util.CellReference;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests that the common CellReference works as we need it to
+ */
+public class TestCellReference extends TestCase {
+       
+       public void testGetCellRefParts() {
+               CellReference cellReference;
+               String[] parts;
+               
+               String cellRef = "A1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(0, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("1", parts[1]);
+               assertEquals("A", parts[2]);
+
+               cellRef = "AA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("1", parts[1]);
+               assertEquals("AA", parts[2]);
+
+               cellRef = "AA100";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("100", parts[1]);
+               assertEquals("AA", parts[2]);
+
+               cellRef = "AAA300";
+               cellReference = new CellReference(cellRef);
+               assertEquals(702, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("300", parts[1]);
+               assertEquals("AAA", parts[2]);
+
+               cellRef = "ZZ100521";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26*26+25, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("100521", parts[1]);
+               assertEquals("ZZ", parts[2]);
+
+               cellRef = "ZYX987";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26*26*26 + 25*26 + 24 - 1, cellReference.getCol());
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("987", parts[1]);
+               assertEquals("ZYX", parts[2]);
+
+               cellRef = "AABC10065";
+               cellReference = new CellReference(cellRef);
+               parts = cellReference.getCellRefParts();
+               assertNotNull(parts);
+               assertEquals(null, parts[0]);
+               assertEquals("10065", parts[1]);
+               assertEquals("AABC", parts[2]);
+       }
+       
+       public void testGetColNumFromRef() {
+               String cellRef = "A1";
+               CellReference cellReference = new CellReference(cellRef);
+               assertEquals(0, cellReference.getCol());
+
+               cellRef = "AA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26, cellReference.getCol());
+
+               cellRef = "AB1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(27, cellReference.getCol());
+
+               cellRef = "BA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26+26, cellReference.getCol());
+               
+               cellRef = "CA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26+26+26, cellReference.getCol());
+               
+               cellRef = "ZA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26*26, cellReference.getCol());
+               
+               cellRef = "ZZ1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26*26+25, cellReference.getCol());
+               
+               cellRef = "AAA1";
+               cellReference = new CellReference(cellRef);
+               assertEquals(26*26+26, cellReference.getCol());
+               
+               
+               cellRef = "A1100";
+               cellReference = new CellReference(cellRef);
+               assertEquals(0, cellReference.getCol());
+
+               cellRef = "BC15";
+               cellReference = new CellReference(cellRef);
+               assertEquals(54, cellReference.getCol());
+       }
+       
+       public void testGetRowNumFromRef() {
+               String cellRef = "A1";
+               CellReference cellReference = new CellReference(cellRef);
+               assertEquals(0, cellReference.getRow());
+
+               cellRef = "A12";
+               cellReference = new CellReference(cellRef);
+               assertEquals(11, cellReference.getRow());
+
+               cellRef = "AS121";
+               cellReference = new CellReference(cellRef);
+               assertEquals(120, cellReference.getRow());
+       }
+       
+       public void testConvertNumToColString() {
+               short col = 702;
+               String collRef = new CellReference(0, col).formatAsString();
+               assertEquals("AAA1", collRef);
+
+               short col2 = 0;
+               String collRef2 = new CellReference(0, col2).formatAsString();
+               assertEquals("A1", collRef2);
+               
+               short col3 = 27;
+               String collRef3 = new CellReference(0, col3).formatAsString();
+               assertEquals("AB1", collRef3);
+               
+               short col4 = 2080;
+               String collRef4 = new CellReference(0, col4).formatAsString();
+               assertEquals("CBA1", collRef4);
+       }
+}
diff --git a/src/testcases/org/apache/poi/ss/util/TestRegion.java b/src/testcases/org/apache/poi/ss/util/TestRegion.java
new file mode 100644 (file)
index 0000000..8cd620d
--- /dev/null
@@ -0,0 +1,49 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss.util;\r
+\r
+import junit.framework.TestCase;\r
+\r
+\r
+/**\r
+ * Tests that the common CellReference works as we need it to\r
+ */\r
+public class TestRegion extends TestCase {\r
+       \r
+       public void testGetRegionRef() {\r
+               int rowFrom = 3;\r
+               short colFrom = 3;\r
+               int rowTo = 9;\r
+               short colTo = 9;\r
+               Region region = new Region(rowFrom, colFrom, rowTo, colTo);\r
+               assertEquals("D4:J10", region.getRegionRef());\r
+       }\r
+       \r
+       public void testContains() {\r
+               int rowFrom = 3;\r
+               short colFrom = 3;\r
+               int rowTo = 9;\r
+               short colTo = 9;\r
+               Region region = new Region(rowFrom, colFrom, rowTo, colTo);\r
+               assertEquals("D4:J10", region.getRegionRef());\r
+               assertTrue(region.contains(5, (short) 7));\r
+               assertTrue(region.contains(9, (short) 9));\r
+               assertFalse(region.contains(9, (short) 10));\r
+       }\r
+       \r
+}\r