Hello!
I`m trying to create a report system by using MSWord 2007, but i have problems with "Template replication".
I have done the code part that opens template and creates a new document, but
document is MESS - borders are erased, tables and captions are in completely different positions, what is unacceptable.
I`m working four days to find solution on MSDN and other popular programming sites, but i can`t figure it out!
Thank you for your time.
I`m creating application that uses Microsoft Word 2007 as a report tool - printing certain documents from their respective templates. It fails to do so. Here is a piece of code:
private void ManagersDoc_Click(object sender, EventArgs e)
{
Object wMissing = System.Reflection.Missing.Value;
Object wTrue = true;
Object wFalse = false;
Word.Application wordApp = new Word.Application();
Word.Document wordDoc = new Word.Document();
wordApp.Visible = true;
Object docPath = @"J:\Quar.dotm";
Template wordDoc = wordApp.Documents.Add(ref docPath, ref wMissing, ref wTrue, ref wTrue);
...
Object oSaveAsFile = @"J:\\SampleDoc.doc";
wordDoc.SaveAs(ref oSaveAsFile, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing, ref wMissing); wordApp.Quit();
We have template of document that is going to be printed, it has:
1) Two tables
2) Captions
3) Markers All is neat, clean and takes 50 roughly percent of sheet.
What code is supposed to do:
1) Create a new Word document from "Quar.dotm" Template.
2) Fill it with data exactly as it is in template
What it does:
1) Create a new word Document from "Quar.dotm" template.
2) Fill it with data in such way that you have to manually place all tables, captions and markers in it.
In addition to that, in preview mode (where MsWord shows how this document will look on paper) everything is split on 2 pages, 2 tables randomly re-sized and scattered across two pages.
IDE: Visual Studio 2010 Language: C# 3.0 Reason why C# 3.0 - app is going to be deployed on Windows XP. .Net Framework version: 3.5 What i`m doing wrong here?