poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r730076 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFSheet.java testcases/org/apache/poi/hssf/data/46445.xls testcases/org/apache/poi/hssf/usermodel/TestBugs.java testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
Date Tue, 30 Dec 2008 09:24:16 GMT
Author: yegor
Date: Tue Dec 30 01:24:15 2008
New Revision: 730076

URL: http://svn.apache.org/viewvc?rev=730076&view=rev
Log:
move hyperlinks when shifting rows

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/46445.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=730076&r1=730075&r2=730076&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Tue Dec 30 01:24:15 2008
@@ -1187,6 +1187,12 @@
                 cellRecord.setRow( rowNum + n );
                 row2Replace.createCellFromRecord( cellRecord );
                 sheet.addValueRecord( rowNum + n, cellRecord );
+
+                HSSFHyperlink link = cell.getHyperlink();
+                if(link != null){
+                    link.setFirstRow(link.getFirstRow() + n);
+                    link.setLastRow(link.getLastRow() + n);
+                }
             }
             // Now zap all the cells in the source row
             row.removeAllCells();

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/46445.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/46445.xls?rev=730076&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/46445.xls
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/46445.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=730076&r1=730075&r2=730076&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Tue Dec 30 01:24:15
2008
@@ -1642,4 +1642,28 @@
         assertEquals("\u0161\u017E\u010D\u0148\u0159", sheet.getRow(1).getCell(0).getStringCellValue());
     }
 
+    /**
+     * Multiple calls of HSSFWorkbook.write result in corrupted xls
+     */
+    public void test32191() throws IOException {
+        HSSFWorkbook wb = openSample("27394.xls");
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+        int size1 = out.size();
+        
+        out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+        int size2 = out.size();
+
+        assertEquals(size1, size2);
+        out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+        int size3 = out.size();
+        assertEquals(size2, size3);
+
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java?rev=730076&r1=730075&r2=730076&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java Tue Dec 30
01:24:15 2008
@@ -184,4 +184,49 @@
         assertNotNull(link);
         assertEquals("http://poi.apache.org/hssf/", link.getAddress());
     }
+
+    /**
+     * Test that HSSFSheet#shiftRows moves hyperlinks,
+     * see bugs #46445 and #29957
+     */
+    public void testShiftRows(){
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46445.xls");
+
+
+        HSSFSheet sheet = wb.getSheetAt(0);
+
+        //verify existing hyperlink in A3
+        HSSFCell cell1 = sheet.getRow(2).getCell(0);
+        HSSFHyperlink link1 = cell1.getHyperlink();
+        assertNotNull(link1);
+        assertEquals(2, link1.getFirstRow());
+        assertEquals(2, link1.getLastRow());
+
+        //assign a hyperlink to A4
+        HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
+        link2.setAddress("Sheet2!A2");
+        HSSFCell cell2 = sheet.getRow(3).getCell(0);
+        cell2.setHyperlink(link2);
+        assertEquals(3, link2.getFirstRow());
+        assertEquals(3, link2.getLastRow());
+
+        //move the 3rd row two rows down
+        sheet.shiftRows(sheet.getFirstRowNum(), sheet.getLastRowNum(), 2);
+
+        //cells A3 and A4 don't contain hyperlinks anymore
+        assertNull(sheet.getRow(2).getCell(0).getHyperlink());
+        assertNull(sheet.getRow(3).getCell(0).getHyperlink());
+
+        //the first hypelink now belongs to A5
+        HSSFHyperlink link1_shifted = sheet.getRow(2+2).getCell(0).getHyperlink();
+        assertNotNull(link1_shifted);
+        assertEquals(4, link1_shifted.getFirstRow());
+        assertEquals(4, link1_shifted.getLastRow());
+
+        //the second hypelink now belongs to A6
+        HSSFHyperlink link2_shifted = sheet.getRow(3+2).getCell(0).getHyperlink();
+        assertNotNull(link2_shifted);
+        assertEquals(5, link2_shifted.getFirstRow());
+        assertEquals(5, link2_shifted.getLastRow());
+    }
 }



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


Mime
View raw message