]> source.dussan.org Git - poi.git/commitdiff
Unit test for #58731 - not reproduced, and some javadocs
authorNick Burch <nick@apache.org>
Wed, 16 Dec 2015 18:15:31 +0000 (18:15 +0000)
committerNick Burch <nick@apache.org>
Wed, 16 Dec 2015 18:15:31 +0000 (18:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1720411 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/POIDocument.java
src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/58731.xlsx [new file with mode: 0644]

index 2131ad8570476f1b517322e87a3e0b478fa2ae0b..aa8ccb37842508348a35d351cc3d8b404ff8220a 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -301,6 +302,10 @@ public abstract class POIDocument {
      * Writes the document out to the specified output stream. The
      * stream is not closed as part of this operation.
      * 
+     * Note - if the Document was opened from a {@link File} rather
+     *  than an {@link InputStream}, you <b>must</b> write out to
+     *  a different file, overwriting via an OutputStream isn't possible.
+     * 
      * @param out The stream to write to.
      * 
      * @throws IOException thrown on errors writing to the stream
index b0b5d4454f0e99999e228246419a233c41eb1d1b..cbb1d80cc7566282c264137f365942124c1400de 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi;
 
 import java.io.Closeable;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -196,6 +197,10 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart implements Close
     /**
      * Write out this document to an Outputstream.
      *
+     * Note - if the Document was opened from a {@link File} rather
+     *  than an {@link InputStream}, you <b>must</b> write out to
+     *  a different file, overwriting via an OutputStream isn't possible.
+     * 
      * @param stream - the java OutputStream you wish to write the file to
      *
      * @exception IOException if anything can't be written.
index 7004ec36d1b808255a9aa4e3c298e6bb8f92160e..ef57ae0693c8d3f23453f9c75e6663c26fd44ce6 100644 (file)
@@ -2850,4 +2850,35 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         assertNotNull(wbBack);
         wbBack.close();
     }
+    
+    public void test58731() throws Exception {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("58731.xlsx");
+        Sheet sheet = wb.createSheet("Java Books");
+        
+        Object[][] bookData = {
+                {"Head First Java", "Kathy Serria", 79},
+                {"Effective Java", "Joshua Bloch", 36},
+                {"Clean Code", "Robert martin", 42},
+                {"Thinking in Java", "Bruce Eckel", 35},
+        };
+        int rowCount = 0;
+        for (Object[] aBook : bookData) {
+            Row row = sheet.createRow(++rowCount);
+             
+            int columnCount = 0;
+            for (Object field : aBook) {
+                Cell cell = row.createCell(++columnCount);
+                if (field instanceof String) {
+                    cell.setCellValue((String) field);
+                } else if (field instanceof Integer) {
+                    cell.setCellValue((Integer) field);
+                }
+            }
+        }
+        
+        Workbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        sheet = wb.getSheet("Java Books");
+        assertEquals(bookData[0][0], sheet.getRow(0).getCell(0).getStringCellValue());
+    }
 }
diff --git a/test-data/spreadsheet/58731.xlsx b/test-data/spreadsheet/58731.xlsx
new file mode 100644 (file)
index 0000000..80e22f3
Binary files /dev/null and b/test-data/spreadsheet/58731.xlsx differ