Last post Nov 24, 2017 06:11 AM by Cathy Zou
Nov 23, 2017 09:11 AM|NAF|LINK
I need to write the first name and last name into word file , this word file contains text but in some paragraphs i need to automatically fill the first name and last name that are located in database , and they are fetched based on a query(this part is
done ) , all what i need to know how can i write them to the word file ? any hint ?
Nov 24, 2017 06:11 AM|Cathy Zou|LINK
Open XML SDK is an good option,
Code as below:
protected void Page_Load(object sender, EventArgs e)
string firstname = "first name ";
string lastname = "last name ";
// Open a WordprocessingDocument for editing using the filepath.
WordprocessingDocument wordprocessingDocument =WordprocessingDocument.Open(@"C:\Users\v-guzou\Desktop\Text.docx", true);
// Assign a reference to the existing document body.
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
// Add new text.
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
Paragraph para1 = body.AppendChild(new Paragraph());
Run run1 = para1.AppendChild(new Run());
Links about How to: Open and add text to a word processing document (Open XML SDK):
Other links for reference: