bokuweb / docx-rs

:memo: A .docx file writer with Rust/WebAssembly.
https://bokuweb.github.io/docx-rs/
MIT License
345 stars 62 forks source link

Reading and then writing shortens the document #597

Open bburdette opened 1 year ago

bburdette commented 1 year ago

Describe the bug

I was going to make a search-and-replace utility, but it looks like the template document doesn't survive reading and writing.

Reproduced step

Here's how far I got. Read in the document, write it again. I had a search and replace step (untested) but that's commented out.

https://github.com/bburdette/docx-template/blob/f2205657daa70795ffe9a177653fadf37df4f77a/src/main.rs#L38

Expected behavior

Expected the same document to be written as as was read in.

Actual behavior

Only the first line is found in the output document.

Screenshots

Input:

image

An error occurs on opening the output file:

image

Proceeding anyway, only the first line survives:

image

Desktop (please complete the following information)

docx-rs = { git = "https://github.com/bokuweb/docx-rs.git", rev="bffbd468e3af9739792bcf2b35eb373aadba4785" }

krsmanian1972 commented 1 year ago

I'm experiencing an identical issue. Looking forward to your help.

krsmanian1972 commented 1 year ago

Describe the Bug:

The error IS due to an unescaped XML Element.

It is most likely to be caused by the Header & Footer style.

The '&' is not escaped and seeps into the XMLDoc, when a source document is read using the read_docx function .

A snapshot from the styles.xml, this was produced by the writer, is here to illustrate the val with an unescaped & character.

**Reproduced Step** Given I create a file using Pages in Mac Then I export that into a docx file Then I read and pack the file as let result = docx.build().pack(new_file); **Actual Behaviour** When I attempt to. open the target file with LibreOffice, I observe the SAX Exception warning. When I attempt to open the target file with Pages, I observe the file can't be opened at this time warning. If I import this file in Google sheet, the sheet brilliantly heals the file. Google sheet is able to render the file without any errors or exception. **Expected Behaviour** The file should be opened without a warning message. Thanks a lot for such a great library.