]> source.dussan.org Git - poi.git/commitdiff
XSSFSheet removeMergedRegion + tests
authorPaolo Mottadelli <paolo@apache.org>
Wed, 9 Apr 2008 20:50:55 +0000 (20:50 +0000)
committerPaolo Mottadelli <paolo@apache.org>
Wed, 9 Apr 2008 20:50:55 +0000 (20:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@646527 13f79535-47bb-0310-9956-ffa450edef68

build.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java

index 5dd4a52fbc51308ea7cc14ba7ab1f15a1a4d1a77..6d39cff4483b3ec629b624b9b4a32c33514cd593 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -202,6 +202,7 @@ under the License.
     <path id="scratchpad.classpath">
         <path refid="main.classpath"/>
         <pathelement location="${main.output.dir}"/>
+       <pathelement location="${scratchpad.output.dir}"/>
     </path>
 
     <path id="contrib.classpath">
@@ -234,6 +235,7 @@ under the License.
 
     <path id="test.ooxml.classpath">
         <path refid="ooxml.classpath"/>
+        <path refid="scratchpad.classpath"/>
         <pathelement location="${ooxml.output.dir}"/>
         <pathelement location="${ooxml.output.test.dir}"/>
         <pathelement location="${main.output.test.dir}"/> <!-- ooxml tests use some utilities from main tests -->
@@ -553,7 +555,7 @@ under the License.
     </javac>
   </target>
 
-  <target name="test" depends="test-main,test-scratchpad,test-contrib"
+  <target name="test" depends="test-main,test-scratchpad,test-contrib,test-ooxml"
     description="Tests main, contrib and scratchpad"/>
 
     <target name="-test-main-check">
@@ -585,6 +587,8 @@ under the License.
           <exclude name="**/All*Tests.java"/>
           <exclude name="**/TestUnfixedBugs.java"/>
           <exclude name="**/TestcaseRecordInputStream.java"/>
+          <exclude name="**/TestRawDataBlock.java"/>
+          <exclude name="**/TestRawDataBlockList.java"/>
         </fileset>
       </batchtest>
     </junit>
@@ -792,6 +796,7 @@ under the License.
                 <fileset dir="${ooxml.src.test}">
                     <include name="**/Test*.java"/>
                     <exclude name="**/All*Tests.java"/>
+                    <exclude name="**/TestExtractorFactory.java"/>
                 </fileset>
             </batchtest>
         </junit>
@@ -1315,7 +1320,7 @@ FORREST_HOME environment variable!</echo>
   <!-- Abort the build if JUnit is missing. -->
   <target name="fail-unless-junit-is-available" depends="init">
     <condition property="isAvailable.junit">
-      <available classname="junit.framework.TestCase"/>
+        <available file="${junit.jar1.dir}"/>
     </condition>
     <antcall target="fail-junit"/>
   </target>
index 08d42db6cd9c785940aa0a2b435c651cb0be20d3..0311599046eb7cc2ff0e63bf3c80db70b4021b07 100644 (file)
@@ -65,7 +65,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState;
 
 
 public class XSSFSheet implements Sheet {
@@ -645,8 +644,16 @@ public class XSSFSheet implements Sheet {
     }
 
     public void removeMergedRegion(int index) {
-        // TODO Auto-generated method stub
-
+       CTMergeCell[] mergeCellsArray = new CTMergeCell[getMergedCells().sizeOfMergeCellArray() - 1];
+       for (int i = 0 ; i < getMergedCells().sizeOfMergeCellArray() ; i++) {
+               if (i < index) {
+                       mergeCellsArray[i] = getMergedCells().getMergeCellArray(i);
+               }
+               else if (i > index) {
+                       mergeCellsArray[i - 1] = getMergedCells().getMergeCellArray(i);
+               }
+       }
+       getMergedCells().setMergeCellArray(mergeCellsArray);
     }
 
     public void removeRow(Row row) {
index a89b14cc6b4e814448800fc43c5e5b958b3ee25d..da73fa8d51b351493fe41e2864449667831c54ef 100644 (file)
@@ -570,6 +570,27 @@ public class TestXSSFSheet extends TestCase {
        assertEquals(1, sheet.getNumMergedRegions());
     }
     
+    public void testRemoveMergedRegion() {
+       Workbook workbook = new XSSFWorkbook();
+       CTSheet ctSheet = CTSheet.Factory.newInstance();
+       CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
+       XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
+       Region region_1 = new Region("A1:B2");
+       Region region_2 = new Region("C3:D4");
+       Region region_3 = new Region("E5:F6");
+       sheet.addMergedRegion(region_1);
+       sheet.addMergedRegion(region_2);
+       sheet.addMergedRegion(region_3);
+       assertEquals("C3:D4", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
+       assertEquals(3, sheet.getNumMergedRegions());
+       sheet.removeMergedRegion(1);
+       assertEquals("E5:F6", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
+       assertEquals(2, sheet.getNumMergedRegions());
+       sheet.removeMergedRegion(1);
+       sheet.removeMergedRegion(0);
+       assertEquals(0, sheet.getNumMergedRegions());
+    }
+    
 
        private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
         XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);