Determine style in MS Word Automation

A

Andrey Dzizenko

Hi all!

AFAIK MS Word has 2 type of styles: like "Style1" and like "Style1 + Font:
10pt".
E.g. Style1 is "Arial 12pt bold". I want to take properties of "Style1
+ Font: 10pt".

1. Style1 is based on another style, I've got how to work with it. If
Range.get_Style().Description contains "+" - I should use Range.Font to
get a font (which is "Arial 10pt bold" while Range.get_Style().Font is
always "Arial 12pt bold"). If Range.get_Style().Description doesn't
contain "+" - the style is default and I can use Range.get_Style().Font.

2. If Style1 is not based on any style ("no style"), I'm in doubt.
Range.get_Style().Description returns "Font: (Style1) Arial 12pt bold"
(without "+", and with 12pt instead of 10pt).

So my question:
Is there a legal way to define if one font is based on another font? Is
there a correct way to collect information about Word document styles?

Best regards,
A. Dzizenko.
 
C

Cindy M.

Hi Andrey,

I'm not certain I'm following everything, here, but...

When you query a style's property (Style.Font.Size for example) it will return
the font size for that style, not the font size of any style it may be based
on. You don't need to parse the Description string to get this information.

If you're looking in the Task pane and seeing "Style1 + 10 pt", then this is
direct formatting that has been applied OVER the style. While Word manages
this like a style in the task pane and in its internal tables YOU cannot work
with the style+formatting combination as a style.

It's not clear what you're trying to do, so at this point I can't do much more
than give you this information. Can you tell us why you need to work with this
information?
AFAIK MS Word has 2 type of styles: like "Style1" and like "Style1 + Font:
10pt".
E.g. Style1 is "Arial 12pt bold". I want to take properties of "Style1
+ Font: 10pt".

1. Style1 is based on another style, I've got how to work with it. If
Range.get_Style().Description contains "+" - I should use Range.Font to
get a font (which is "Arial 10pt bold" while Range.get_Style().Font is
always "Arial 12pt bold"). If Range.get_Style().Description doesn't
contain "+" - the style is default and I can use Range.get_Style().Font.

2. If Style1 is not based on any style ("no style"), I'm in doubt.
Range.get_Style().Description returns "Font: (Style1) Arial 12pt bold"
(without "+", and with 12pt instead of 10pt).

So my question:
Is there a legal way to define if one font is based on another font? Is
there a correct way to collect information about Word document styles?

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 :)
 
A

Andrey Dzizenko

I just try to get if my style is based on another style. Is there a way to
do it?

I want to get the information about formatting from the style if it's
possible and truthful, or to get this information from the range if the
range formatted over the style.
I want to know if the range is "over-formatted".
 
C

Cindy M.

Hi Andrey,
I just try to get if my style is based on another style. Is there a way to
do it?
Taking your question very literally:

Style.BaseStyle

But this has nothing to do with whether the user has applied formatting to
the text, over the style.
I want to get the information about formatting from the style if it's
possible and truthful, or to get this information from the range if the
range formatted over the style.
I want to know if the range is "over-formatted".
I think the only way you can determine this would be to compare each aspect
of the Range with the corresponding part of the styles definition.

There's nothing in Word's object model that will do a global comparison for
you and tell you whether the formatting in the range is different from the
definition of the style that's been applied to it.

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 :)
 
A

Andrey Dzizenko

I think the only way you can determine this would be to compare each
aspect
of the Range with the corresponding part of the styles definition.

You can't imagine how long time this process can take. Every calling of
any property in the automation is VERY slow...
 

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