Home All Groups Group Topic Archive Search About
Author
28 Nov 2007 7:15 PM
lsg
Hi,
Anybody know how to open docx (MS Word) file, retrive all formfields,
insert text and print in c# ?

Best Regards
Leszek

Author
28 Nov 2007 9:10 PM
Peter Bromberg [C# MVP]
You have two choices:
1) use the Word Object model by setting a COM tab reference to the
appropriate version of Word.

2)Since docx files are XML, parse the Xml with the Office Xml APIs:

http://msdn2.microsoft.com/en-us/library/ms406049.aspx

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Show quote
"lsg" wrote:

> Hi,
> Anybody know how to open docx (MS Word) file, retrive all formfields,
> insert text and print in c# ?
>
> Best Regards
> Leszek
>
Author
29 Nov 2007 12:28 AM
Tom Shelton
On Nov 28, 2:10 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote:
> You have two choices:
> 1) use the Word Object model by setting a COM tab reference to the
> appropriate version of Word.
>
> 2)Since docx files are XML, parse the Xml with the Office Xml APIs:
>

Docx files are not xml.  They are zip files that contain the xml
files.  To open them and manipulate their contents, the OP will want
to look at the System.IO.Packaging namepsace from .NET 3.0 and above.

--
Tom Shelton
Author
29 Nov 2007 2:30 AM
Arne_Vajhøj
Tom Shelton wrote:
> On Nov 28, 2:10 pm, Peter Bromberg [C# MVP]
> <pbromb...@yahoo.NoSpamMaam.com> wrote:
>> You have two choices:
>> 1) use the Word Object model by setting a COM tab reference to the
>> appropriate version of Word.
>>
>> 2)Since docx files are XML, parse the Xml with the Office Xml APIs:
>
> Docx files are not xml.  They are zip files that contain the xml
> files.  To open them and manipulate their contents, the OP will want
> to look at the System.IO.Packaging namepsace from .NET 3.0 and above.

On older .NET versions it should be possible to use #ZipLib to
get a Stream and use that by XmlDocument Load.

Arne
Author
29 Nov 2007 2:57 AM
Tom Shelton
On Nov 28, 7:30 pm, Arne Vajhøj <a***@vajhoej.dk> wrote:
Show quote
> Tom Shelton wrote:
> > On Nov 28, 2:10 pm, Peter Bromberg [C# MVP]
> > <pbromb...@yahoo.NoSpamMaam.com> wrote:
> >> You have two choices:
> >> 1) use the Word Object model by setting a COM tab reference to the
> >> appropriate version of Word.
>
> >> 2)Since docx files are XML, parse the Xml with the Office Xml APIs:
>
> > Docx files are not xml.  They are zip files that contain the xml
> > files.  To open them and manipulate their contents, the OP will want
> > to look at the System.IO.Packaging namepsace from .NET 3.0 and above.
>
> On older .NET versions it should be possible to use #ZipLib to
> get a Stream and use that by XmlDocument Load.
>
> Arne

Sure - it should definately be possible.  If you change the name of a
docx file to name.zip, you can actually open it with windows explorer,
just like a normal zip archive.

--
Tom Shelton
Author
29 Nov 2007 12:20 PM
Peter Bromberg [C# MVP]
Good poiint, and I have done this several times.  Should have said "zipped
xml"!

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Show quote
"Tom Shelton" wrote:

> On Nov 28, 7:30 pm, Arne Vajhøj <a***@vajhoej.dk> wrote:
> > Tom Shelton wrote:
> > > On Nov 28, 2:10 pm, Peter Bromberg [C# MVP]
> > > <pbromb...@yahoo.NoSpamMaam.com> wrote:
> > >> You have two choices:
> > >> 1) use the Word Object model by setting a COM tab reference to the
> > >> appropriate version of Word.
> >
> > >> 2)Since docx files are XML, parse the Xml with the Office Xml APIs:
> >
> > > Docx files are not xml.  They are zip files that contain the xml
> > > files.  To open them and manipulate their contents, the OP will want
> > > to look at the System.IO.Packaging namepsace from .NET 3.0 and above.
> >
> > On older .NET versions it should be possible to use #ZipLib to
> > get a Stream and use that by XmlDocument Load.
> >
> > Arne
>
> Sure - it should definately be possible.  If you change the name of a
> docx file to name.zip, you can actually open it with windows explorer,
> just like a normal zip archive.
>
> --
> Tom Shelton
>

AddThis Social Bookmark Button