1

I am writing an application using ColdBox / ORM. For my problem, I am attempting to have HTML code rendered / downloaded with an .docx file extension rather than a .doc file extension. When downloading the rendered document and trying to open it, I receive a popup saying

Word found unreadable content in ***********. Do you want to recover the contents of this document?

.cfm page

In the file I am trying to have rendered, there is the following in the html tag

 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:w="urn:schemas-microsoft-com:office:word"
 xmlns="http://www.w3.org/TR/REC-html40"

.cfc page

original code

event.renderData(data=fileReadBinary('fileName.doc')
      , contentType='application/msword'
      , isBinary=true);

new code

event.renderData(data=fileReadBinary('fileName.docx')
       , contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
       , isBinary=true);

My expected output is to have the contents of the .cfm file rendered in a .docx file and to be able to open and view it. What actually happens is I get some popup saying "Word found unreadable content in ***********. Do you want to recover the contents of this document?" With buttons for yes / no. Even when choosing yes, I do not see the contents of the file. However, the current code successfully renders as a .doc file which I can view / open.

Community
  • 1
  • 1
John
  • 21
  • 2

1 Answers1

0

As @Ageax mentioned, docx, is a much more complicated file. They are actually zip files. If you take a .docx and rename it to .zip, you can open it and inspect what actually goes into a .docx. You should find the content in the /word/document.xml file of the zip. Instead of trying to create one from scratch, you may want to set up a template of the document that you are trying to create with placeholders. You can unzip the template, edit the document.xml file with your data, zip and rename to docx.

MattInVail
  • 13
  • 5
  • That's what I was thinking too. However, apparently Word may [split text across multiple tags](https://stackoverflow.com/questions/17701497/why-office-openxml-splits-text-between-tags-and-how-to-prevent-it) in some cases. So a simple search and replace on {placeholder} may fail. Which is a shame because it's simple and elegant solution. – SOS Oct 12 '19 at 19:49