Last post Jul 23, 2015 09:20 AM by Boris Pavlovic
Jun 30, 2015 05:13 AM|a-rad|LINK
I have a series of word documents that I want to use my Razor skills to build a better way of filling them out. At present they are filled out by hand then printed out.
What I am proposing is using data that sits in a database to 'fill' out the forms. What is the best way of doing this?
The simplest solution that I have working is converting the word doc into a HTML page and populating it with an SQL query - Works fine. I haven't found a decent Word to HTML converter though :(
Interested to see if anyone has gone down this path?
Jul 08, 2015 02:58 AM|Angie xu - MSFT|LINK
I haven't found a decent Word to HTML converter though :(
It's recommended to add reference to OpenXmlPowerTools.dll, and convert .docx file to HTML format
byte byteArray = File.ReadAllBytes(DocxFilePath);
using (MemoryStream memoryStream = new MemoryStream())
memoryStream.Write(byteArray, 0, byteArray.Length);
using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
HtmlConverterSettings settings = new HtmlConverterSettings()
PageTitle = "My Page Title"
XElement html = HtmlConverter.ConvertToHtml(doc, settings);
Jul 08, 2015 05:01 AM|a-rad|LINK
Will this enable me to use the doc and add information into it? Or simply convert it?
Jul 12, 2015 10:22 AM|Angie xu - MSFT|LINK
This will help convert it before you use the doc document.
Jul 19, 2015 07:32 AM|PatriceSc|LINK
What do you want? Do you want to add information to a Word document and send this document client side or convert it to HTML? See perhaps
Jul 23, 2015 09:20 AM|Boris Pavlovic|LINK
Check out this document generation toolkit. You can use Word document as templates and then populate them with the data from the database. The toolkit doesn't use Office COM which makes it a suitable solution for Asp.NET
applications. What you need to do is just creating a Word document, inserting tags/placeholders and then calling
several lines of code to populate the template document with the data:
// Load products from the database.
IEnumerable<Product> products = DataAccess.GetProducts();
// Create report engine and provide 'products' as the value for the default data source.
DocumentGenerator dg = new DocumentGenerator(products);
// Execute document generation by specifying the template and the output document.
DocumentGenerationResult result = dg.GenerateDocument("Template.docx", "GeneratedDocument.docx");
foreach (Error error in result.Errors) Console.WriteLine(error);