Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to use OpenXML with word 2007 template?

I want to replace the template markers

and generate the document

in asp.net c #

sorry for my English is very bad I'm learning

Help
Posted

1 solution

Does it have to be a real template? I am asking because that implies some sort of "mail merge" type process, which can't/shouldn't be done on the server.
If you can use a regular Word document,
the Open XML [^] will generate a class for creating the doc in which you can replace the 'template' fields with the real data.

In the generated code, it will look something like this:

Run run1 = new Run();
Text text1 = new Text();
text1.Text = "This is a fake template, and here is the DATA1";
run1.Append(text1);
paragraph1.Append(run1);


but you'd change it to this:

Run run1 = new Run();
Text text1 = new Text();
text1.Text = "This is a fake template, and here is the "+DATA1;
run1.Append(text1);
paragraph1.Append(run1);


And replace all your variables at runtime.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900