Hello, I am planning to build a functionality that will read a word template and then replace certain sections with data pulled from DB. I am planning to use Office.Word.Document to read the template then use function "FindAndReplace".
My question is will this work in Azure when I deploy? Or there is some other design?
Naimish MakwanaPosted May 13, 2024, 2:49 PM
Your approach of using
Office.Word.Documentand theFindAndReplacefunction to manipulate Word documents can work locally, but it might not work in Azure. The reason is thatOffice.Word.Documentrelies on the Office Interop services, which require the Office suite to be installed on the machine where the code is running. In the case of Azure, the Office suite is not installed on the server, so the Office Interop services are not available1.However, there are other ways to manipulate Word documents in Azure:
Syncfusion DocIO: This is a .NET library that can create, read, and edit Word documents without requiring Microsoft Office2. You can use this library to replace certain sections of your Word template with data from your database.
Microsoft Graph API with OneDrive: You can save your Word document to OneDrive and then use the Microsoft Graph API to read and edit the document1. This approach allows you to edit Word documents online, which can be a good choice if you want to provide an experience similar to SharePoint1.
Open XML SDK: This is a set of .NET libraries that can read, write, and create documents in Open XML format, which is the default Word document format (.docx). You can use this library to manipulate your Word template.
Remember to choose the approach that best fits your requirements and constraints.
Thanks
Leon DPosted May 15, 2024, 1:22 AM
Hi,
You can use Free Spire.Doc for .NET (https://www.e-iceblue.com/Introduce/free-doc-component.html) for this purpose. The library supports various scenarios for finding and replacing text, including finding and replacing text with new text, finding and replacing text with image, finding and replacing text using regex, finding and replacing text with table, finding and replacing text with another Word document, and more.
Here is the documentation on how to find and replace text in Word in C# using this library:
https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/NET-Word-Replace-String-in-Word-with-New-String-in-C-VB.NET.html