docx
docx copied to clipboard
Cant open .docx file created with docx.js in MS office word, only if i use OpenOffice writter
Thank you for raising an issue to docx
Please do not raise an issue unless it is an issue.
-
Is your issue a feature request? Are you giving ideas to the community? Are you asking for help? Please raise a ticket in the
Discussionssection:https://github.com/dolanmiu/docx/discussions
-
Is your issue a previously asked? Please respond to that thread instead
when i try to open a docx file created with docx.js api in MS office word, i receive a unspecified error. I created the file with the getting starded basic usage demo.
Hi @dvjuncal Please provide the code so we can reproduce & fix or point out mistakes
They code si the one in "Basic usage" section. I'm using ms office 2007, maybe thats the problema. Code:
import * as fs from "fs"; import { Document, Packer, Paragraph, TextRun } from "docx"; // Documents contain sections, you can have multiple sections per document, go here to learn more about sections // This simple example will only contain one section const doc = new Document({ sections: [{ properties: {}, children: [ new Paragraph({ children: [ new TextRun("Hello World"), new TextRun({ text: "Foo Bar", bold: true, }), new TextRun({ text: "\tGithub is the best", bold: true, }), ], }), ], }], }); // Used to export the file into a .docx file Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); }); // Done! A file called 'My Document.docx' will be in your file
El mié., 24 de noviembre de 2021 18:52, Andrey Savin < @.***> escribió:
Hi @dvjuncal https://github.com/dvjuncal Please provide the code so we can reproduce & fix or point out mistakes
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dolanmiu/docx/issues/1311#issuecomment-978291980, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPWIBWQ3HFZCH5LR57SM3DUNVNBTANCNFSM5IWUJBVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
what is the error?
When i try to open the generated file with ms office word 2007 this message appears:
[image: image.png]
*In english it means: *
"The file My Document cannot be opened because there are problems with the contents" "Details: Unspecified Error" "Location: /word/document.xml, line 1, column 3782"
But if i try to open it with OpenOffice Writer, i have no problem.
I think its a compatibility issue with office 2007.
Regards Diego
El jue, 25 nov 2021 a las 13:43, Dolan @.***>) escribió:
what is the error?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dolanmiu/docx/issues/1311#issuecomment-979352495, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPWIBWZOWILYWHQTRJ2RNDUNZRUXANCNFSM5IWUJBVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
https://github.com/dolanmiu/docx/blob/35d987430a05253730b943e703e591d833aa5cb9/src/file/document/body/section-properties/section-properties.ts#L78-L86 seems like office word 2007 doesn't understand "1in", i tried to replace "1in" with specific number, it works fine.
Ok, I will normalise it to use numbers (TWIPS)
I do not know if this is intentional but I have also noticed that if I use
....
const buffer = Packer.toBuffer(docxVar);
..
I cannot open the file in Word(only in Open Office), whereas if I use
...
const base64StrDoc = Packer.toBase64String(docxVar)
...
instead, and then save the file, or stream the file with
...
Buffer.from(base64StrDoc, 'base64')
...
it works just fine. Is toBuffer broken?