aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Mottadelli <paolo@apache.org>2008-04-06 20:34:00 +0000
committerPaolo Mottadelli <paolo@apache.org>2008-04-06 20:34:00 +0000
commitba8c1c39a730e7002fd3f983c475be3b8c5015d1 (patch)
treef1d9405922b5fcd638e137494dccdc5a27ede002
parent4e01cda4ae9ee792bcf007fe6a737772d3d90e5c (diff)
downloadpoi-ba8c1c39a730e7002fd3f983c475be3b8c5015d1.tar.gz
poi-ba8c1c39a730e7002fd3f983c475be3b8c5015d1.zip
XSSFSheet addMergedRegion + Region class moved to org.apache.poi.ss.util.Region + Region.getRegionRef method + tests
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645303 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java2
-rw-r--r--src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java2
-rw-r--r--src/java/org/apache/poi/hssf/dev/HSSF.java1
-rw-r--r--src/java/org/apache/poi/hssf/record/CFHeaderRecord.java2
-rw-r--r--src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java2
-rw-r--r--src/java/org/apache/poi/hssf/record/cf/CellRange.java2
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java2
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java2
-rw-r--r--src/java/org/apache/poi/ss/util/Region.java (renamed from src/java/org/apache/poi/hssf/util/Region.java)12
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java17
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java2
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestCellReference.java (renamed from src/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java)2
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestRegion.java49
19 files changed, 92 insertions, 18 deletions
diff --git a/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java b/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
index f587f022fe..ea525149c7 100644
--- a/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
+++ b/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
@@ -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;
diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
index c44d81617f..fa66d76f0a 100644
--- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
+++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
@@ -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;
diff --git a/src/java/org/apache/poi/hssf/dev/HSSF.java b/src/java/org/apache/poi/hssf/dev/HSSF.java
index 7dddca966a..4302357c47 100644
--- a/src/java/org/apache/poi/hssf/dev/HSSF.java
+++ b/src/java/org/apache/poi/hssf/dev/HSSF.java
@@ -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.*;
diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
index d74d54ab17..224f5e5c19 100644
--- a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
+++ b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
@@ -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;
/**
diff --git a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
index 81154ebb22..d91269ed34 100644
--- a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
+++ b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
@@ -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;
diff --git a/src/java/org/apache/poi/hssf/record/cf/CellRange.java b/src/java/org/apache/poi/hssf/record/cf/CellRange.java
index f45b79b003..41cb4a2a29 100644
--- a/src/java/org/apache/poi/hssf/record/cf/CellRange.java
+++ b/src/java/org/apache/poi/hssf/record/cf/CellRange.java
@@ -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;
/**
*
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
index d9e470a68c..6a08c4b304 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
@@ -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.
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index 4aad1e1b18..ca0c126f42 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -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/ss/util/Region.java
index 67d52eb137..e44026cde2 100644
--- a/src/java/org/apache/poi/hssf/util/Region.java
+++ b/src/java/org/apache/poi/ss/util/Region.java
@@ -16,7 +16,7 @@
==================================================================== */
-package org.apache.poi.hssf.util;
+package org.apache.poi.ss.util;
import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion;
@@ -218,4 +218,14 @@ public class Region
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;
+ }
}
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
index fe533b2841..e9fd943ba8 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
@@ -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> {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index d6106ff20e..50ae19b896 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -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/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index f05c1d1157..119556c225 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -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.*;
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
index a663602ed3..6a0b151581 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
@@ -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.
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
index 34885e7a21..2c28edf3ac 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
@@ -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.*;
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
index 5dcc61aa41..d03a3a4071 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
@@ -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
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 13eafa4fd8..f3283677b9 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -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;
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
index efe726a6a5..bf6953e785 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
@@ -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/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java b/src/testcases/org/apache/poi/ss/util/TestCellReference.java
index 79a1c3717b..f13b221134 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/util/TestCellReference.java
+++ b/src/testcases/org/apache/poi/ss/util/TestCellReference.java
@@ -15,7 +15,7 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.xssf.util;
+package org.apache.poi.ss.util;
import org.apache.poi.ss.util.CellReference;
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
index 0000000000..8cd620d38c
--- /dev/null
+++ b/src/testcases/org/apache/poi/ss/util/TestRegion.java
@@ -0,0 +1,49 @@
+/* ====================================================================
+ 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 junit.framework.TestCase;
+
+
+/**
+ * Tests that the common CellReference works as we need it to
+ */
+public class TestRegion extends TestCase {
+
+ public void testGetRegionRef() {
+ int rowFrom = 3;
+ short colFrom = 3;
+ int rowTo = 9;
+ short colTo = 9;
+ Region region = new Region(rowFrom, colFrom, rowTo, colTo);
+ assertEquals("D4:J10", region.getRegionRef());
+ }
+
+ public void testContains() {
+ int rowFrom = 3;
+ short colFrom = 3;
+ int rowTo = 9;
+ short colTo = 9;
+ Region region = new Region(rowFrom, colFrom, rowTo, colTo);
+ assertEquals("D4:J10", region.getRegionRef());
+ assertTrue(region.contains(5, (short) 7));
+ assertTrue(region.contains(9, (short) 9));
+ assertFalse(region.contains(9, (short) 10));
+ }
+
+}