473,378 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Document.Open Office Example

Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activate();
wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian
Jan 16 '06 #1
4 18599
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #2
Fabian,
you need to ensure the document actually exists at the path specified, and
that you have all upper and lower casing exact.
For example, this path:

object path = "C:\\temp\\Test.doc";

would open "Test.doc" from the C:\temp folder.
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Fabian" wrote:
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activate();
wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #3
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #4
Sorry, I forgot to say :

I use
VS2005.NET C#
Office2003
Windows2000


"Fabian" wrote:
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian" <Fa****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Application wordapp = new Word.Application();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documents.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activate();

wordapp.Selection.TypeText("TEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEST");
wordapp.Selection.TypeParagraph();
worddoc.Save();
wordapp.Documents.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Emily John | last post by:
I have a word document that I need to send it as an attachment to an XML file. Basically, converting into byte array or using some encoding mechanism. This has to be done through XML serialization...
8
by: Asma | last post by:
Dear Sir, I am trying to find a way to open a Word document using C language and read the text of word doc into a variable. (Turbo C on Dos 6.0). Can anyone please tell me which libraries in...
1
by: Marco Moioli | last post by:
Hi, I have a problem with a X509 digital signature. I want to sign a Word 2003 document saved in .xml format. the problem is that after the signature, Word 2003 don't want to open the document. ...
1
by: Gary | last post by:
Hi, there, 1. I would like to open a word document in a MDI environment. Every time, a new window outside my MDI poped out and show the word document. Is there a method I can use to specify the...
4
by: Jon Westmore | last post by:
I'm using an ASP page to dynamically generate an XML document using a data source. I was thinking the concept would be similar to dynamically creating HTML but I'm running into an issue. Here is...
0
by: Karel | last post by:
Hi, I have developed a vb.net application to create a mail-merged document by using Automation to word from VB.NET. I added the following reference to the application: Microsoft Office 10.0...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
9
by: tubby | last post by:
Silly question, but here goes... what's a good way to determine when a file is an Open Office document? I could look at the file extension, but it seems there would be a better way. VI shows this...
2
by: saketmayur | last post by:
Hi , I have write the following code to open word document on server using Microsoft.Office.Interop.Word; string DocPath = System.Configuration.ConfigurationManager.AppSettings; ...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.