diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
index 8cf5cbc0e2..524672863f 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
@@ -298,7 +298,7 @@ public class SheetDataWriter implements Closeable {
String value = cell.getStringCellValue();
if(value != null && !value.isEmpty()) {
_out.write("");
- _out.write(value);
+ outputQuotedString(value);
_out.write("");
}
break;
@@ -311,7 +311,7 @@ public class SheetDataWriter implements Closeable {
FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
_out.write(">");
- _out.write(error.getString());
+ outputQuotedString(error.getString());
_out.write("");
break;
}
@@ -358,7 +358,7 @@ public class SheetDataWriter implements Closeable {
writeAttribute("t", "e");
_out.write(">");
- _out.write(error.getString());
+ outputQuotedString(error.getString());
_out.write("");
break;
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
index 174b1c4905..44d06dcd33 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
@@ -238,4 +238,30 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
}
}
}
+
+ @Test
+ public void test64595() throws Exception {
+ try (Workbook workbook = new SXSSFWorkbook(100)) {
+ Sheet sheet = workbook.createSheet("RawData");
+ Row row = sheet.createRow(0);
+ Cell cell;
+
+ cell = row.createCell(0);
+ cell.setCellValue("Ernie & Bert");
+
+ cell = row.createCell(1);
+ // Set a precalculated formula value containing a special character.
+ cell.setCellValue("Ernie & Bert are cool!");
+ cell.setCellFormula("A1 & \" are cool!\"");
+
+ // While unfixed reading the workbook would throw a POIXMLException
+ // since the file was corrupt due to missing quotation.
+ try (Workbook wbBack = SXSSFITestDataProvider.instance.writeOutAndReadBack(workbook)) {
+ assertNotNull(wbBack);
+ cell = wbBack.getSheetAt(0).getRow(0).getCell(1);
+ assertEquals("Ernie & Bert are cool!", cell.getStringCellValue());
+ assertEquals("A1 & \" are cool!\"", cell.getCellFormula());
+ }
+ }
+ }
}