Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Replace text in word document

Explorer ,
Feb 13, 2019 Feb 13, 2019

Using a recent version of ColdFusion that has the built in POI library, using HWPF or XWPF (it does not matter which one), does anyone have sample code that would read a word file from the server, replace text (for example: replace "*test*" with "12345") and then output this new version of the file to the browser? No need to save the file. Pushing the new file data via cfcontent is what I am looking for.

Any help would be appreciated. Thank you in advance.

969
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2019 Feb 13, 2019

Someone in the CF Community posted something that you might want to read.

https://coldfusion.adobe.com/2018/11/extracting-text-html-out-word-docx-files/

HTH,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2019 Feb 13, 2019

Thank you for this. I watched the video, but this is not really what I need.

I need to edit a Word document and then push it to the browser in Word format (doc or docx). The video explains how to convert a Word document into xml format and display in a browser.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2019 Feb 13, 2019

But you can take that XML, modify it, save it to a variable and produce it to the browser.

Well, maybe I'm over-simplifying it, but that was the thought that was in my head.

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2019 Feb 13, 2019

I tried modifying the xml by just changing a word in the source data. When I saved it and tried to open it, Word could not open the file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2019 Feb 13, 2019

I've been looking around, and I have yet to see anything Word related that CF can work well with.  I know for a fact that CFSPREADSHEET and SpreadsheetNew() work most excellent with Excel files, but I've never needed to work with Word files.

I know CFDOCUMENT can convert .doc/.docx files to PDF.  Would that suffice?  Convert the Word file to PDF, then manipulate the PDF and serve that to the user?

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2019 Feb 13, 2019

Thanks for looking. I looked myself and could not find a ColdFusion example.

I agree that the ColdFusion spreadsheet functions are really good.

What I need to do, is generate a Word template pre-filled with db data that users will then manipulate. That is why it needs to be in Word.

cfdocument or cfhtmltopdf would do the trick if there was an easy way to convert the pdf to word after the pdf was generated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2019 Feb 13, 2019
LATEST

Not in CF, AFAIK.  You might find some third party application that can do that, use DirectoryWatch to kick off the process once the PDF has been saved to a particular folder, perhaps.

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources