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;
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;
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.*;
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;
/**
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;
import java.util.Arrays;
import java.util.List;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
/**
*
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.
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;
+++ /dev/null
-/* ====================================================================
- 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())));
- }
-}
--- /dev/null
+/* ====================================================================
+ 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;
+ }
+}
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> {
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;
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;
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;
protected ColumnHelper columnHelper;
protected XSSFWorkbook workbook;
protected CommentsSource sheetComments;
+ protected CTMergeCells ctMergeCells;
public static final short LeftMargin = 0;
public static final short RightMargin = 1;
}
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);
}
+++ /dev/null
-/* ====================================================================
- 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);
- }
-}
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.*;
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.
import junit.framework.TestCase;
import org.apache.poi.hssf.util.*;
+import org.apache.poi.ss.util.Region;
import java.io.*;
import java.util.*;
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
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;
/**
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;
--- /dev/null
+/* ====================================================================
+ 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);
+ }
+}
--- /dev/null
+/* ====================================================================\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