diff options
author | Nick Burch <nick@apache.org> | 2015-12-16 18:15:31 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-12-16 18:15:31 +0000 |
commit | 83334b9fd165afdd17032b0d5b19d71c7c727626 (patch) | |
tree | 42a6e4e1dd264d14222849a06287678bf2209298 /src | |
parent | 2ac3e0f3e8a8d94bcc493ddc19793b831dfc854a (diff) | |
download | poi-83334b9fd165afdd17032b0d5b19d71c7c727626.tar.gz poi-83334b9fd165afdd17032b0d5b19d71c7c727626.zip |
Unit test for #58731 - not reproduced, and some javadocs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1720411 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/poi/POIDocument.java | 5 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/POIXMLDocument.java | 5 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java | 31 |
3 files changed, 41 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java index 2131ad8570..aa8ccb3784 100644 --- a/src/java/org/apache/poi/POIDocument.java +++ b/src/java/org/apache/poi/POIDocument.java @@ -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 diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocument.java b/src/ooxml/java/org/apache/poi/POIXMLDocument.java index b0b5d4454f..cbb1d80cc7 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocument.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocument.java @@ -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. diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 7004ec36d1..ef57ae0693 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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()); + } } |