I need to create an word document based on the template in c#. I have tags for only the paragraphs. Is there any way to replace the bullets and tables that are already available in the template based on the user input.
I was able to replace the paragraph with input text using the Replace command in the Word InterOp.
Need help to do the rest of the items.
- Replace the bullets based on the user input
- Fill the tables with the input values
Code for replacing the Paragraph based on the tag:
FindAndReplace(wordApplication, "/date/", DateTime.Now.Date.ToString("MMM dd, yyyy"));
FindAndReplace(){
wordApplication.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
ref matchAllWordsForms, ref forward, ref wrap, ref format, ref repl开发者_如何学CaceWithText, ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamsa, ref matchControl);
}
Thanks in Advance. ASAP
I'd suggest putting bookmarks into your Word document and using them to assign data.
object oBookMark = "MyBookmark";
oWordDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here";
You can populate tables using this method and I imagine you should be able to populate bullet points.
This is the generally accepted way to programmatically populate a Word template. Matching strings is difficult to write and maintain accurately and can easily yield unexpected results. With a bookmark, you know what data you're assigning and exactly where it's going.
Take a look at this Coderush project.
精彩评论