Highlighted

Replace text in word document

Explorer ,
Feb 13, 2019

Copy link to clipboard

Copied

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.

Views

242

Likes

Translate

Translate

Report

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

Replace text in word document

Explorer ,
Feb 13, 2019

Copy link to clipboard

Copied

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.

Views

243

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
Explorer ,
Feb 13, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
LEGEND ,
Feb 13, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
Explorer ,
Feb 13, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
LEGEND ,
Feb 13, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
Explorer ,
Feb 13, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0
LEGEND ,
Feb 13, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2019 0