Click here to Skip to main content
15,896,201 members

Comments by Aleonis (Top 4 by date)

Aleonis 29-Apr-12 8:28am View    
Well, i looked at the format, added format type: wdFormatDocument and added .docx instead of simply .Doc.

Now i`m getting error: "type mismatch HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)"

Here is the code:
Object oSaveFileFormat = (Object)"wdFormatDocument";
wordDoc.SaveAs2(ref oSaveAsFile,
ref oSaveFileFormat,
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);


I`ve tried also to leave format (wdFormatDocument parameter) as wMissing, while changing .doc to .docx - no effect. Error is still here...
Aleonis 28-Apr-12 10:52am View    
Saving data to the table depends on another algorithm that is going to be tested after is sort this one out. I have updated my question and it contains code and description now.
I`m trying to understand why my piece of code creates document according to a template (what was intended), but breaks order and position of information in created document (what was not supposed to happen at all) every time i execute code mentioned in my 1st message.
Aleonis 28-Apr-12 10:04am View    
Deleted
Hello Wes Aday and thank you for response, i will clarify.
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"; // Path to Document Template
wordDoc = wordApp.Documents.Add(ref docPath, ref wMissing, ref wTrue, ref wTrue);

... // Interaction with Database PostgeSQL 9.1.2.

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?
Aleonis 28-Apr-12 10:03am View    
Deleted
Hello Richard and thank you for your response, i will clarify.
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"; // Path to Document Template
wordDoc = wordApp.Documents.Add(ref docPath, ref wMissing, ref wTrue, ref wTrue);

... // Interaction with Database PostgeSQL 9.1.2.

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?