Mutley2003
asked on
Getting "styles" for paragraphs in a Word document (from Delphi)
Suppose I have a Word document with user defined styles for paragraphs. Like "headline" and "comment" as well as the inbuilt Heading1 etc.
I want to iterate across paragraphs and, for each, extract (to some file)
a) the text of the paragraph
b) the name of the associated style
c) the characteristics of that style (eg font name and size)
How can I do that in delphi? ( I know how to open a Word doc in delphi with automation, but it is the various collections that confuse me)
thanks
I want to iterate across paragraphs and, for each, extract (to some file)
a) the text of the paragraph
b) the name of the associated style
c) the characteristics of that style (eg font name and size)
How can I do that in delphi? ( I know how to open a Word doc in delphi with automation, but it is the various collections that confuse me)
thanks
For the styles, the vba help give a sample
// vba code
// Create the new style named 'Introduction'
Set myStyle = ActiveDocument.Styles.Add(
With myStyle.Font
.Bold = True
.Italic = True
.Name = "Arial"
.Size = 12
End With
// apply the style to the selected paragraph
Selection.Range.Style = "Introduction"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Bernani, I will try to do some tests .. I think that should be enough to get me started.
You need a range to do what you're asking. See the vba help for all the option (if needed, Alt+F11 in Word give you access to the vba editor - vba help isn't installed by default, you need install it)
Maybe this could help:
var vParam: OleVariant;
FPara: Paragraph;
FRange: Range;
cDoc: string;
begin
cDoc := 'c:\document.doc';
vParam := cDoc;
WordApplication1.Connect;
try
WordApplication1.Documents
WordDocument1.ConnectTo(Wo
// working with the opened document
// chose your paragraph
FPara := WordDocument1.Paragraphs.I
// choose a word
FRange := FPara.Range.Words.Item(2);
// Word in bold
FRange.Bold := 1;
and so on ....