From 83334b9fd165afdd17032b0d5b19d71c7c727626 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 16 Dec 2015 18:15:31 +0000 Subject: [PATCH] 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 --- src/java/org/apache/poi/POIDocument.java | 5 +++ .../java/org/apache/poi/POIXMLDocument.java | 5 +++ .../poi/xssf/usermodel/TestXSSFBugs.java | 31 ++++++++++++++++++ test-data/spreadsheet/58731.xlsx | Bin 0 -> 9023 bytes 4 files changed, 41 insertions(+) create mode 100644 test-data/spreadsheet/58731.xlsx 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 must 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 must 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()); + } } diff --git a/test-data/spreadsheet/58731.xlsx b/test-data/spreadsheet/58731.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..80e22f3d17b6eef7156e1d3d51e5e710e12209ac GIT binary patch literal 9023 zcmeHNWmHsc*B(+*y1NIEMnFLtrKLM&fT25;F6r(@8bMO&5{4F#kdP6OMkOU3K)%uU zeO`UgZ>{gw_vd}itaa`+>zsYfnft!3z4yKMQBy)eB?h1aFaQ7m1HjilgVY`g0CadW=?hVjflmR*i2MIJ{)=Z|B*j<>%1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