diff --git a/pom.xml b/pom.xml index 09ec812..343f763 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.miachm.sods SODS jar - 1.5.2 + 1.5.3 Simple ODS library A library for load/save ODS files in java. @@ -71,6 +71,7 @@ Bundle-SymbolicName: com.github.miachm.sods Automatic-Module-Name: com.github.miachm.sods -jpms-module-info: com.github.miachm.sods + -sources: true ]]> true diff --git a/src/com/github/miachm/sods/OdsWritter.java b/src/com/github/miachm/sods/OdsWriter.java similarity index 93% rename from src/com/github/miachm/sods/OdsWritter.java rename to src/com/github/miachm/sods/OdsWriter.java index d52ef9d..4277444 100644 --- a/src/com/github/miachm/sods/OdsWritter.java +++ b/src/com/github/miachm/sods/OdsWriter.java @@ -10,7 +10,7 @@ /** * Internal class for generate ODS files. */ -class OdsWritter { +class OdsWriter { private final static String office = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; private final static String table_namespace = "urn:oasis:names:tc:opendocument:xmlns:table:1.0"; private final static String text_namespace = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; @@ -27,14 +27,14 @@ class OdsWritter { private Map tableStyleStringMap = new HashMap<>(); private final String MIMETYPE= "application/vnd.oasis.opendocument.spreadsheet"; - private OdsWritter(OutputStream o, SpreadSheet spread) { + private OdsWriter(OutputStream o, SpreadSheet spread) { this.spread = spread; this.out = new Compressor(o); spread.trimSheets(); } public static void save(OutputStream out,SpreadSheet spread) throws IOException { - new OdsWritter(out,spread).save(); + new OdsWriter(out,spread).save(); } private void save() throws IOException { @@ -266,36 +266,43 @@ private void writeValue(XMLStreamWriter out, Cell cell) throws XMLStreamExceptio Object v = cell.getValue(); if (v != null) { OfficeValueType valueType = OfficeValueType.ofJavaType(v.getClass()); - valueType.write(v, out); - out.writeStartElement("text:p"); String text = v.toString(); + if (text.contains(System.lineSeparator())) { + valueType.write("", out); - for (int i = 0; i < text.length(); i++) { - if (text.charAt(i) == ' ') { - out.writeStartElement("text:s"); - int cnt = 0; - while (i+cnt < text.length() && text.charAt(i + cnt) == ' ') { - cnt++; + out.writeStartElement("text:p"); + + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == ' ') { + out.writeStartElement("text:s"); + int cnt = 0; + while (i+cnt < text.length() && text.charAt(i + cnt) == ' ') { + cnt++; + } + if (cnt > 1) + out.writeAttribute("text:c", "" + cnt); + i += cnt - 1 ; + out.writeEndElement(); } - if (cnt > 1) - out.writeAttribute("text:c", "" + cnt); - i += cnt - 1 ; - out.writeEndElement(); - } - else if (text.charAt(i) == '\t') { - out.writeEmptyElement("text:tab"); - } - else if (text.charAt(i) == '\n') { - out.writeEndElement(); - out.writeStartElement("text:p"); + else if (text.charAt(i) == '\t') { + out.writeEmptyElement("text:tab"); + } + else if (text.charAt(i) == '\n') { + out.writeEndElement(); + out.writeStartElement("text:p"); + } + else + out.writeCharacters("" + text.charAt(i)); } - else - out.writeCharacters("" + text.charAt(i)); - } - out.writeEndElement(); + out.writeEndElement(); + + } else { + valueType.write(v, out); + } } + OfficeAnnotation annotation = cell.getAnnotation(); if (annotation != null) { out.writeStartElement("office:annotation"); diff --git a/src/com/github/miachm/sods/SpreadSheet.java b/src/com/github/miachm/sods/SpreadSheet.java index d2e6011..3bee4bf 100644 --- a/src/com/github/miachm/sods/SpreadSheet.java +++ b/src/com/github/miachm/sods/SpreadSheet.java @@ -195,7 +195,7 @@ public void save(File out) throws IOException { * @throws IOException In case of an io error. */ public void save(OutputStream out) throws IOException { - OdsWritter.save(out,this); + OdsWriter.save(out,this); } /**