Use word template with Xceed.Docx


Xceed.Words.Net is a library for generating word file without using the office library. You need not to install the office for create word file from your C# application.

I have plenty of beautiful Microsoft template, which I used create reports. So what I need is to use those template with Xceed. The idea sound good, isn’t it.

Lets place all your templates inside folder, in your debug folder and use it in your Xceed code as follows

using (var document = Xceed.Words.NET.DocX.Create(fname))
{
 document.ApplyTemplate(@"doctemplates /CashLedger.dotx");
document.ReplaceText("[MyCompany]", ViewModels_Variables.ModelViews.CompanyProfile[0].company);
                    document.ReplaceText("[Clandmark]", " | " + ViewModels_Variables.ModelViews.CompanyProfile[0].lmark);
                    document.ReplaceText("[CCity]", " | " + ViewModels_Variables.ModelViews.CompanyProfile[0].place); 
document.Save();
document.Dispose();}

My template folder simply named templates and use @”doctemplates /CashLedger.dotx” to locate the application path folder.

Here is a sample document template

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.