Convert file from docx to odt with LibreOffice

I have docx file that when I convert it to odt with LibreOffice by CLI it not opened with Microsoft Office (but opened by LibreOffice). my Command:

libreoffice --headless --convert-to odt sample.docx

When I save it with LibreOffice GUI to odt it open in both (Opened in Microsoft Office and LibreOffice)
I’m very confused and I do not know what is the reason for this file corruption.

My docx file : Link
My odt converted file with LibreOffice CLI that is corrupt: Link

How do you mean that it is corrupted? Recent versions of MS Office can open .odt files. So, if the default application to open .odt files is set to MS Word, then Word will open it. That’s not corruption, that’s how your operating system works. It’s odd if Windows starts both programs with your file, that’s another matter. Please give more information.

please download odt file that is converted from docx with above commad, then open it with libreoffice and microsoft office. you can see ms-office cannot open it and say this file is corrupt. or: download docx file in my question and convert it with above command to odt. then open it with ms office and say again this file is corrupt.

then open it with libreoffice and microsoft office

Don’t assume users of LibreOffice do have MS Office as well.

@anon73440385 i want to upload it for another person and he has only ms office.

@anon87010807 can you test it?

I don’t have MS Office. But LibreOffice can save files in .docx format, so what’s the problem?

The .odt loads just fine, no corruption reported. Lorem Ipsum sample, repeated a few times. What’s wrong with it on your side?

@anon87010807 Thanks. Yes LibreOffice open it correctly. but Ms Office not.
I do not know if there is a problem with my conversion or a bug

I finally got what you mean. Right, so the command line conversion fails, while opening in Writer and saving as .odt works fine. I’m a practical man. Don’t use the command line conversion method. :wink: You might compare the .odt files - they’re zip archives, so extract the contents to two different folders, then compare the two sets. Maybe you can file a bug report. See How to Report Bugs in LibreOffice - The Document Foundation Wiki for help with that.

Maybe it’s an issue with the odt version that MS it’s able to open fine, test saving with 1.2 not extended Menu/Tools/Options/Load&Save/General - ODF save version.

Yes, I repro MS Word 2016 unable to open an ODT produced from your DOCX sample from command line, while being able to open GUI-generated ODT. This is a bug in MS Word, which fails to read the document with missing optional style:column-width attribute of style:table-column-properties element in content.xml. The absence of the said attribute is normal and expected; it is only added when saved from GUI as a cached value to speed up following opening of the file (since when opened in GUI mode, LibreOffice processes the layout to show on screen, and thus has the calculated values ready, which is obvuiosly not performed in command-line version, which does not layout the document), and in its absence, application should just use style:rel-column-width to calculate the resulting column width.

See the reference in ODF standard; here is its RNG schema.

Nothing to be done on LibreOffice side.

MS documentation mentions this deficiency in [MS-OODF3]:

This attribute (i.e., style:rel-column-width - comment mine) is not supported in Word 2013, Word 2016, or Word 2019.

which means that they can’t properly read valid ODF that only have relative column widths.

Also worth noting that in ODF up to version 1.1, there was some confusion in standard regarding requirement of style:column-width attribute: the schema told it’s optional, while there was text stating otherwise:

15.9.1 Column Width

Every table column must have a fixed width. This width is specified by the style:column-width attribute.

The width of a column may be also specified relative to the other column widths.

This was corrected in ODF 1.2, which MS claims to support since Word 2013.