From 483231db52237055338a72f36ce60a59e1ae4352 Mon Sep 17 00:00:00 2001 From: Miguel Chacon Date: Fri, 22 Dec 2023 04:27:42 +0000 Subject: [PATCH] Fix issue #85 with string values in Excel --- resources/excelFileStringValue.ods | Bin 0 -> 2482 bytes resources/features/bugs/crashExcel.feature | 3 +-- src/com/github/miachm/sods/OdsWritter.java | 7 +++++-- src/com/github/miachm/sods/OfficeValueType.java | 2 +- .../github/miachm/sods/OfficeValueTypeTest.java | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 resources/excelFileStringValue.ods diff --git a/resources/excelFileStringValue.ods b/resources/excelFileStringValue.ods new file mode 100644 index 0000000000000000000000000000000000000000..0e1f1583974a0967bb59e70bc3b66687e5bb8af9 GIT binary patch literal 2482 zcmaKuc{J2tAIHZ&Cd=3+Bun;Pma>*5!Wc#vWMoTXP>&hHh#?dPlbsOpOxeR&ezIgs z))z7 z@zK^WV_O47GfNX?KR18x8=h#4Qm~(Ix-}Hkp#p9(?Y$X zOz;d8Us;05Bb>TU-id-Y{ua3M8ETVY+``DzK{ryVE5S+R3?^OA!pisJs|mjT%i?3_ z;}$g|IqT<2a9s6i{JHZW8|keLhD?U>7ZTlBOL$$|3?#mv=e^bex8_++n!AAk*okwAmhtKU#XG% z(O1k+hijVX?AuPe!Iiv71TX72;l(U0ouynO^6)4_jIUO_0xe#NHvc)p3EHm5Eq{!s z|1Wb_ou&dtO?bo8PX~Sg*f>UN>K5PErwf|p*zd}UDtAn?1L!NT=P`k1DsY0 z9l5+@LzU2z@BNU@qsB1?;)oO|*Nga(H&s--XzISxYs~uu-C@)BX*y%HrU4vx7cw0D zaWYgb_=f*2z2)_qkq3Llr&KN`m?~I2?xqjtlIiho`12bc-{Tx>lN012^pGUKuLL#K z9j8#p&RKmj+f2f-@@0!18h!y{2n4gE^PMil+h$WEbk|F&Ona1)zG=5_AWMLov(8uS zt4j}xQI2M>Iw5l&@?RCXxl7WoTJ~2j)cgy=&gv3a3OG>?v#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TYug?{P=@9ZzlCv+Bd&b1e2Kq34qIr+V4 zHf{YBN?yRUa9Ms5aeH1GSk>(BBk8Q(E_c>NgZw46l!kz`nK^Nt4DIT2HYrD{h` zXFeiKG%ZO(xGt^_k``m)U8dB`*U*C5r{V@-jf$;_wLfvhv)Rj5L!W~^=$9AR%Y6PU z1hF+*pFNo(c4Bx8!&Jm>DtEN?FGf*vho=W%wpuQIb{>*#-qOT( z;WO~X)nJC6?=#xBJXhtHnp@`c8XBgDuzu8l6GM~f(pXU`$FKS@1b$t6;f2wmpo(tQ ze2C9RSn#8yZ!a!{pnrT8Z)vqA!8Tu2Pt_kn+WltWlA{6>I#ZSvDOv-cGYRjY1Ky#D za>N?UAMquQ$OxvnCa8Q?6s%wBmg68l>RJA(|JlL7p@03waZ(=<|F@WE z-NAqP|M#fl{vA>Lx4dXk$C&>2z~i?$viG-GXxV?84Tmz(o(BM6qzww~Tl1^7{{V8% BE}H-V literal 0 HcmV?d00001 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