Discussion:
Interop.Word.Paragraph.Style Question
(too old to reply)
David
2006-07-29 02:41:01 UTC
Permalink
Hi all,

I'm using Interop.Word in order to retrieve all paragraph styles of a word
document. However, once I use the code such as:

"object style = document.Paragraphs[i].Style;"

The Visual Studio compiler display:

"Property, indexer, or event 'Style' is not supported by the language; try
directly calling accessor methods
'Microsoft.Office.Interop.Word.Paragraph.get_Style()' or
'Microsoft.Office.Interop.Word.Paragraph.set_Style(ref object)' "

I think it's about managed code and unmanaged code conflict, but I've no
idea how to fix it. Does anyone know how to fix it?


Thanks Forum.
Cindy M -WordMVP-
2006-07-29 14:40:25 UTC
Permalink
Hi =?Utf-8?B?RGF2aWQ=?=,
Post by David
I'm using Interop.Word in order to retrieve all paragraph styles of a word
"object style = document.Paragraphs[i].Style;"
"Property, indexer, or event 'Style' is not supported by the language; try
directly calling accessor methods
'Microsoft.Office.Interop.Word.Paragraph.get_Style()' or
'Microsoft.Office.Interop.Word.Paragraph.set_Style(ref object)' "
I think it's about managed code and unmanaged code conflict, but I've no
idea how to fix it. Does anyone know how to fix it?
The compiler is doing a pretty good job of telling you what you need - I've
encountered worse :-)

Word.Style style = document.Paragraphs[i].get_Style();
MessageBox.Show(style.NameLocal);

The reason is a bit technical, but in "plain English": C# requires on strong
typing, unlike the way Word VBA is designed to work. The "interpreter" (PIA)
"translates" some of the VBA things into structures C# can work with. In this
case, a method pair - get_Style and set_Style - are substituted for the
.Style property.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
David
2006-07-31 07:46:01 UTC
Permalink
Thanks Cindy
Post by Cindy M -WordMVP-
Hi =?Utf-8?B?RGF2aWQ=?=,
Post by David
I'm using Interop.Word in order to retrieve all paragraph styles of a word
"object style = document.Paragraphs[i].Style;"
"Property, indexer, or event 'Style' is not supported by the language; try
directly calling accessor methods
'Microsoft.Office.Interop.Word.Paragraph.get_Style()' or
'Microsoft.Office.Interop.Word.Paragraph.set_Style(ref object)' "
I think it's about managed code and unmanaged code conflict, but I've no
idea how to fix it. Does anyone know how to fix it?
The compiler is doing a pretty good job of telling you what you need - I've
encountered worse :-)
Word.Style style = document.Paragraphs[i].get_Style();
MessageBox.Show(style.NameLocal);
The reason is a bit technical, but in "plain English": C# requires on strong
typing, unlike the way Word VBA is designed to work. The "interpreter" (PIA)
"translates" some of the VBA things into structures C# can work with. In this
case, a method pair - get_Style and set_Style - are substituted for the
.Style property.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Loading...