Closed juergen-albert closed 4 years ago
Hi. It's suprising because I never experienced this behavior (the tutorial is extracted out of integration tests, hence it is regularly tested). Does LibreOffice says the file is corrupted? (LO should yell.)
I just tested this code with the 0.7.2 version:
final OdsFactory odsFactory = OdsFactory.create(Logger.getLogger("hello-world"), Locale.US);
final AnonymousOdsFileWriter writer = odsFactory.createWriter();
final OdsDocument document = writer.document();
final Table table = document.addTable("hello-world");
final TableRowImpl row = table.getRow(0);
final TableCell cell = row.getOrCreateCell(0);
cell.setStringValue("Hello, world!");
writer.saveAs(new File("generated_files", "a_hello_world_example.ods"));
And got a valid ODS file. The content of content.xml
is valid:
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
office:version="1.2">
<office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="Liberation Sans"/></office:font-face-decls>
<office:automatic-styles>
<style:style style:name="ta1" style:family="table" style:master-page-name="DefaultMasterPage"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style>
<style:style style:name="ro1" style:family="table-row"><style:table-row-properties style:row-height="0.45cm" fo:break-before="auto"/></style:style>
<style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="2.5cm"/></style:style>
</office:automatic-styles>
<office:body>
<office:spreadsheet>
<table:table table:name="hello-world" table:style-name="ta1" table:print="false"><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="Default"/>
<table:table-row table:style-name="ro1"><table:table-cell table:style-name="Default" office:value-type="string" office:string-value="Hello, world!"/></table:table-row>
</table:table>
</office:spreadsheet>
</office:body>
</office:document-content>
Can you share the code you executed (just copy paste from your project)?
My code looks as follows:
final OdsFactory odsFactory = OdsFactory.create();
final AnonymousOdsFileWriter writer = odsFactory.createWriter();
final OdsDocument document = writer.document();
Table table;
try {
table = document.addTable("hello-world");
final TableRowImpl row = table.getRow(0);
final TableCell cell = row.getOrCreateCell(0);
cell.setStringValue("Hello, world!");
writer.save(System.out);
writer.saveAs(new File("generated", "readme_example4.zip"));
System.out.println("done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I've added the write to System.out right from the start out of curiosity. I've just realized that this is the offending line. When I remove it, I the resulting content.xml is correct.
After a bit of fiddling with it: using the writer more then once, causes the problem (I guess this is not the commen usecase). The first write is valid and every following run is missing the start tag.
Thanks! This is very interesting. This is indeed not the common use case, but this should not happen or be documented. I'll further investigate.
I think this is fixed. I took the opportunity to add an optional parameter to save
that allows to tune the zip writer, in this case to set the compression level to 0 in order to make the output readable.
Code:
final OdsFactory odsFactory = OdsFactory.create(Logger.getLogger("hello-world"), Locale.US);
final AnonymousOdsFileWriter writer = odsFactory.createWriter();
final OdsDocument document = writer.document();
final Table table = document.addTable("hello-world");
final TableRowImpl row = table.getRow(0);
final TableCell cell = row.getOrCreateCell(0);
cell.setStringValue("Hello, world!");
writer.save(System.out, ZipUTF8WriterImpl.builder().level(Deflater.NO_COMPRESSION));
writer.saveAs(new File("generated_files", "a_hello_world_example.ods"));
Output:
PK 䦩P Thumbnails/ ��PK PK 䦩P ' Configurations2/accelerator/current.xml ��PK PK 䦩P Configurations2/floater/ ��PK PK 䦩P Configurations2/images/Bitmaps/ ��PK PK 䦩P Configurations2/menubar/ ��PK PK 䦩P Configurations2/popupmenu/ ��PK PK 䦩P Configurations2/progressbar/ ��PK PK 䦩P Configurations2/statusbar/ ��PK PK 䦩P Configurations2/toolbar/ ��PK PK 䦩P mimetype. ��application/vnd.oasis.opendocument.spreadsheetPK�l9�3 . PK 䦩P meta.xmlw��<?xml version="1.0" encoding="UTF-8"?><office:document-meta xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.2"><office:meta><dc:creator>jferard</dc:creator><dc:date>2020-05-09T18:55:09</dc:date><dc:language>fr</dc:language><meta:generator>FastOds/0.7.3</meta:generator><meta:editing-cycles>1</meta:editing-cycles><meta:editing-duration>PT1M00S</meta:editing-duration></office:meta></office:document-meta>PK��| w PK 䦩P
styles.xml2��<?xml version="1.0" encoding="UTF-8"?><office:document-styles xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.2"><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="Liberation Sans"/></office:font-face-decls><office:styles><style:style style:name="Default" style:family="table-cell"><style:table-cell-properties style:vertical-align="top"/><style:text-properties style:font-name="Liberation Sans"/><style:paragraph-properties fo:margin="0cm"/></style:style><style:style style:name="Header" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"><style:paragraph-properties text:number-lines="false" text:line-number="0"/></style:style><style:style style:name="Footer" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"><style:paragraph-properties text:number-lines="false" text:line-number="0"/></style:style></office:styles><office:automatic-styles><style:style style:name="none" style:family="text"><style:text-properties/></style:style><style:page-layout style:name="Mpm1"><style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" style:num-format="1" style:writing-mode="lr-tb" style:print-orientation="portrait" fo:margin="1.5cm"/><style:header-style><style:header-footer-properties fo:min-height="0cm" fo:margin="0cm"/></style:header-style><style:footer-style><style:header-footer-properties fo:min-height="0cm" fo:margin="0cm"/></style:footer-style></style:page-layout></office:automatic-styles><office:master-styles><style:master-page style:name="Mpm1" style:page-layout-name="Mpm1"><style:header><text:p><text:span text:style-name="none"></text:span></text:p></style:header><style:header-left style:display="false"/><style:footer><text:p><text:span text:style-name="none"></text:span></text:p></style:footer><style:footer-left style:display="false"/></style:master-page></office:master-styles></office:document-styles>PK�* 7 2 PK 䦩P content.xml�
a�<?xml version="1.0" encoding="UTF-8"?><office:document-content xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" office:version="1.2"><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="Liberation Sans"/></office:font-face-decls><office:automatic-styles><style:style style:name="ta1" style:family="table" style:master-page-name="DefaultMasterPage"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style><style:style style:name="ro1" style:family="table-row"><style:table-row-properties style:row-height="0.45cm" fo:break-before="auto"/></style:style><style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="2.5cm"/></style:style></office:automatic-styles><office:body><office:spreadsheet><table:table table:name="hello-world" table:style-name="ta1" table:print="false"><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell table:style-name="Default" office:value-type="string" office:string-value="Hello, world!"/></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>PK9�أ
�
PK 䦩P settings.xml�J�<?xml version="1.0" encoding="UTF-8" ?><office:document-settings xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" office:version="1.2"><office:settings><config:config-item-set config:name="ooo:view-settings"><config:config-item config:name="VisibleAreaTop" config:type="int">0</config:config-item><config:config-item config:name="VisibleAreaLeft" config:type="int">0</config:config-item><config:config-item-map-indexed config:name="Views"><config:config-item-map-entry><config:config-item config:name="RasterSubdivisionX" config:type="long">1</config:config-item><config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item><config:config-item config:name="IsSnapToRaster" config:type="boolean">false</config:config-item><config:config-item config:name="RasterSubdivisionY" config:type="long">1</config:config-item><config:config-item config:name="ZoomType" config:type="short">0</config:config-item><config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">true</config:config-item><config:config-item config:name="HorizontalScrollbarWidth" config:type="int">270</config:config-item><config:config-item config:name="ShowZeroValues" config:type="boolean">true</config:config-item><config:config-item config:name="ShowNotes" config:type="boolean">true</config:config-item><config:config-item config:name="GridColor" config:type="long">12632256</config:config-item><config:config-item config:name="IsRasterAxisSynchronized" config:type="boolean">true</config:config-item><config:config-item config:name="RasterResolutionX" config:type="long">1000</config:config-item><config:config-item config:name="ShowPageBreakPreview" config:type="boolean">false</config:config-item><config:config-item config:name="ZoomValue" config:type="short">100</config:config-item><config:config-item config:name="RasterResolutionY" config:type="long">1000</config:config-item><config:config-item config:name="ActiveTable" config:type="string">Sheet1</config:config-item><config:config-item config:name="HasColumnRowHeaders" config:type="boolean">true</config:config-item><config:config-item config:name="ViewId" config:type="string">View1</config:config-item><config:config-item-map-named config:name="Tables"><config:config-item-map-entry config:name="hello-world"><config:config-item config:name="PositionBottom" config:type="int">0</config:config-item><config:config-item config:name="HorizontalSplitMode" config:type="short">0</config:config-item><config:config-item config:name="ZoomType" config:type="short">0</config:config-item><config:config-item config:name="ActiveSplitRange" config:type="short">2</config:config-item><config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item><config:config-item config:name="VerticalSplitPosition" config:type="int">0</config:config-item><config:config-item config:name="ZoomValue" config:type="short">100</config:config-item><config:config-item config:name="PositionTop" config:type="int">0</config:config-item><config:config-item config:name="HorizontalSplitPosition" config:type="int">0</config:config-item><config:config-item config:name="CursorPositionX" config:type="int">0</config:config-item><config:config-item config:name="PageViewZoomValue" config:type="int">60</config:config-item><config:config-item config:name="CursorPositionY" config:type="int">0</config:config-item><config:config-item config:name="PositionRight" config:type="int">0</config:config-item><config:config-item config:name="PositionLeft" config:type="int">0</config:config-item></config:config-item-map-entry></config:config-item-map-named><config:config-item config:name="PageViewZoomValue" config:type="int">60</config:config-item><config:config-item config:name="RasterIsVisible" config:type="boolean">false</config:config-item><config:config-item config:name="HasSheetTabs" config:type="boolean">true</config:config-item><config:config-item config:name="ShowPageBreaks" config:type="boolean">true</config:config-item></config:config-item-map-entry></config:config-item-map-indexed><config:config-item config:name="VisibleAreaWidth" config:type="int">680</config:config-item><config:config-item config:name="VisibleAreaHeight" config:type="int">400</config:config-item></config:config-item-set><config:config-item-set config:name="ooo:configuration-settings"><config:config-item config:name="RasterSubdivisionX" config:type="long">1</config:config-item><config:config-item config:name="IsSnapToRaster" config:type="boolean">false</config:config-item><config:config-item config:name="RasterSubdivisionY" config:type="long">1</config:config-item><config:config-item config:name="AllowPrintJobCancel" config:type="boolean">true</config:config-item><config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">true</config:config-item><config:config-item config:name="UpdateFromTemplate" config:type="boolean">true</config:config-item><config:config-item config:name="CharacterCompressionType" config:type="short">0</config:config-item><config:config-item config:name="ShowZeroValues" config:type="boolean">true</config:config-item><config:config-item config:name="AutoCalculate" config:type="boolean">true</config:config-item><config:config-item config:name="RasterResolutionX" config:type="long">1000</config:config-item><config:config-item config:name="LoadReadonly" config:type="boolean">false</config:config-item><config:config-item config:name="RasterResolutionY" config:type="long">1000</config:config-item><config:config-item config:name="ApplyUserData" config:type="boolean">true</config:config-item><config:config-item config:name="RasterIsVisible" config:type="boolean">false</config:config-item><config:config-item config:name="HasSheetTabs" config:type="boolean">true</config:config-item><config:config-item config:name="ShowPageBreaks" config:type="boolean">true</config:config-item><config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item><config:config-item config:name="ShowNotes" config:type="boolean">true</config:config-item><config:config-item config:name="GridColor" config:type="long">12632256</config:config-item><config:config-item config:name="LinkUpdateMode" config:type="short">3</config:config-item><config:config-item config:name="PrinterSetup" config:type="base64Binary"></config:config-item><config:config-item config:name="IsRasterAxisSynchronized" config:type="boolean">true</config:config-item><config:config-item config:name="SaveVersionOnClose" config:type="boolean">false</config:config-item><config:config-item config:name="IsKernAsianPunctuation" config:type="boolean">false</config:config-item><config:config-item config:name="PrinterName" config:type="string"></config:config-item><config:config-item config:name="HasColumnRowHeaders" config:type="boolean">true</config:config-item></config:config-item-set></office:settings></office:document-settings>PK�4䔺 � PK 䦩P META-INF/manifest.xml,��<?xml version="1.0" encoding="UTF-8" ?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"><manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/><manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="Configurations2/" manifest:media-type="application/vnd.sun.xml.ui.configuration"/><manifest:file-entry manifest:full-path="Configurations2/statusbar/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/accelerator/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/accelerator/current.xml" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/floater/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/popupmenu/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/progressbar/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/menubar/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/toolbar/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/images/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Configurations2/images/Bitmaps/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Thumbnails/" manifest:media-type=""/><manifest:file-entry manifest:full-path="Thumbnails/thumbnail.png" manifest:media-type=""/></manifest:manifest>PK�-1 , PK 䦩P Thumbnails/PK 䦩P ' > Configurations2/accelerator/current.xmlPK 䦩P � Configurations2/floater/PK 䦩P � Configurations2/images/Bitmaps/PK 䦩P 5 Configurations2/menubar/PK 䦩P � Configurations2/popupmenu/PK 䦩P � Configurations2/progressbar/PK 䦩P Configurations2/statusbar/PK 䦩P i Configurations2/toolbar/PK 䦩P�l9�3 . � mimetypePK 䦩P��| w meta.xmlPK 䦩P�* 7 2
� styles.xmlPK 䦩P9�أ
�
> content.xmlPK 䦩P�4䔺 � settings.xmlPK 䦩P�-1 , 9 META-INF/manifest.xmlPK � �@
And the file is valid.
If I use your example from the Readme.MD a corrupt ods is created. A
</table:table>
is there, but the opening tag is missing. If tried the Versions 0.7.0 and 0.7.2.The Error is in the content.xml, which looks as follows: