Interop.Word.Paragraph.Style Question

D

David

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.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.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQ=?=,
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.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?

The compiler is doing a pretty good job of telling you what you need - I've
encountered worse :)

Word.Style style = document.Paragraphs.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 :)
 
D

David

Thanks Cindy

Cindy M -WordMVP- said:
Hi =?Utf-8?B?RGF2aWQ=?=,
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.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?

The compiler is doing a pretty good job of telling you what you need - I've
encountered worse :)

Word.Style style = document.Paragraphs.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)


This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top