diff --git a/resources/excelFileStringValue.ods b/resources/excelFileStringValue.ods new file mode 100644 index 0000000..0e1f158 Binary files /dev/null and b/resources/excelFileStringValue.ods differ diff --git a/resources/features/bugs/crashExcel.feature b/resources/features/bugs/crashExcel.feature index 80133af..aaa18b7 100644 --- a/resources/features/bugs/crashExcel.feature +++ b/resources/features/bugs/crashExcel.feature @@ -10,9 +10,8 @@ Feature: Bugs related to loading a file generated by SODS in Excel Then the tag is "office:document-styles" Scenario: Excel does not read values - When load a spreadsheet from the resource "emptyCell" + When load a spreadsheet from the resource "excelFileStringValue" And save the spreadsheet in the memory And gets the "content.xml" entry in the spreadsheet saved in the memory And gets the first tag "table:table-cell" of the xml entry Then the tag has the attribute "office:value-type" with the value "string" - Then the tag has the attribute "office:value" with the value "Test 1" diff --git a/src/com/github/miachm/sods/OdsWritter.java b/src/com/github/miachm/sods/OdsWritter.java index a8ec6dd..978d33b 100644 --- a/src/com/github/miachm/sods/OdsWritter.java +++ b/src/com/github/miachm/sods/OdsWritter.java @@ -283,9 +283,12 @@ private void writeValue(XMLStreamWriter out, Cell cell) throws XMLStreamExceptio LibreOffice only writes the "string-value" attribute for formulaic cells. Writing it for non-formulaic cells makes LibreOffice discard newlines when opening the sheet. */ - //if (valueType != OfficeValueType.STRING || cell.getFormula() != null) { + if (valueType != OfficeValueType.STRING || cell.getFormula() != null) { valueType.write(v, out); - //} + } + else if (valueType == OfficeValueType.STRING) { + out.writeAttribute(OFFICE, "value-type", "string"); + } out.writeStartElement(TEXT, "p"); String text = v.toString(); diff --git a/src/com/github/miachm/sods/OfficeValueType.java b/src/com/github/miachm/sods/OfficeValueType.java index 02c743a..5c48f65 100644 --- a/src/com/github/miachm/sods/OfficeValueType.java +++ b/src/com/github/miachm/sods/OfficeValueType.java @@ -176,7 +176,7 @@ public Object read(XmlReaderInstance reader) { public void write(Object value, XMLStreamWriter writer) throws XMLStreamException { if (value instanceof String) { writer.writeAttribute(OFFICE, "value-type", this.getId()); - writer.writeAttribute(OFFICE, "value", value.toString().replace("\n", " ")); + writer.writeAttribute(OFFICE, "string-value", value.toString().replace("\n", " ")); } } }, diff --git a/tests/com/github/miachm/sods/OfficeValueTypeTest.java b/tests/com/github/miachm/sods/OfficeValueTypeTest.java index ee8822c..cc8f21a 100644 --- a/tests/com/github/miachm/sods/OfficeValueTypeTest.java +++ b/tests/com/github/miachm/sods/OfficeValueTypeTest.java @@ -166,11 +166,11 @@ public void testReadString() throws Exception { public void testWriteString() throws Exception { assertWrite(OfficeValueType.STRING, "hello") .containsAttribute("office:value-type", "string") - .containsAttribute("office:value", "hello"); + .containsAttribute("office:string-value", "hello"); assertWrite(OfficeValueType.STRING, "see\nyou") .containsAttribute("office:value-type", "string") - .containsAttribute("office:value", "see you"); + .containsAttribute("office:string-value", "see you"); } @Test