Hi all,
Does anyone have a sample for Word automation. I want to read a document (.doc) make some changes (like font for some lines) and save it.
Thanks all
George
Hi George,
First create a new module (e.g. _MsWord) and import the autoation server for Word.
Here is a little method that does what you want.
METHOD DoOpenWord(cFileName) CLASS StandardSDIWindow
LOCAL oWord AS WDApplication
LOCAL oDoc AS WDDocument
LOCAL oDocs AS WDDocuments
LOCAL oSelection AS WDSelection
LOCAL oFind AS WDFind
LOCAL lRet AS LOGIC
LOCAL uTemp AS USUAL
oWord := WDApplication{}
oDocs := oWord:Documents
oWord:Visible := TRUE // FALSE
oDoc := oDocs:Open(cFileName)
oSelection := oWord:Selection
oSelection:HomeKey( 6, 0 )
oFind := oSelection:Find
oFind:ClearFormatting()
oFind:Text := "Veranstaltung"
lRet := oFind:Execute()
IF lRet
oSelection := oWord:Selection
oSelection:Style := oSelection:Document:Styles:Item("Überschrift 1") oSelection:Font:Italic := TRUE
oSelection:Font:Size := 25.1
uTemp := oSelection:Font:Underline := TRUE
oDoc:Save()
oWord:Quit()
ENDIF
/*
Selection.Find.ClearFormatting
With Selection.Find
.Text = "200677"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
*/
RETURN NIL
Best regards
Norbert
On Monday, May 15, 2023 at 10:48:48 PM UTC+2, Γεωργιος Τριτσος wrote:
Hi all,
Does anyone have a sample for Word automation. I want to read a document (.doc) make some changes (like font for some lines) and save it.
Thanks all
George
Στις Τρίτη 16 Μαΐου 2023 στις 4:10:17 μ.μ. UTC+3, ο χρήστης Norbert Kolb έγραψε:Hi Norbert,
Hi George,
First create a new module (e.g. _MsWord) and import the autoation server for Word.
Here is a little method that does what you want.
METHOD DoOpenWord(cFileName) CLASS StandardSDIWindow
LOCAL oWord AS WDApplication
LOCAL oDoc AS WDDocument
LOCAL oDocs AS WDDocuments
LOCAL oSelection AS WDSelection
LOCAL oFind AS WDFind
LOCAL lRet AS LOGIC
LOCAL uTemp AS USUAL
oWord := WDApplication{}
oDocs := oWord:Documents
oWord:Visible := TRUE // FALSE
oDoc := oDocs:Open(cFileName)
oSelection := oWord:Selection
oSelection:HomeKey( 6, 0 )
oFind := oSelection:Find
oFind:ClearFormatting()
oFind:Text := "Veranstaltung"
lRet := oFind:Execute()
IF lRet
oSelection := oWord:Selection
oSelection:Style := oSelection:Document:Styles:Item("Überschrift 1") oSelection:Font:Italic := TRUE
oSelection:Font:Size := 25.1
uTemp := oSelection:Font:Underline := TRUE
oDoc:Save()
oWord:Quit()
ENDIF
/*
Selection.Find.ClearFormatting
With Selection.Find
.Text = "200677"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
*/
RETURN NIL
Best regards
Norbert
On Monday, May 15, 2023 at 10:48:48 PM UTC+2, Γεωργιος Τριτσος wrote:
Hi all,
Does anyone have a sample for Word automation. I want to read a document (.doc) make some changes (like font for some lines) and save it.
Thanks all
Hi Norbert,George
Thanks for reply. I will try your method.
Regards
George
Hi George,Hi Norbert,
did you create the automation server for word first. All the classes and methods you need for Word are generated there.
Vo menu: Tools -> Automation Server (Word)
The error message indicates that the programme cannot find these classes.
Kind regards
Norbert
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 47:14:27 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,066 |
Messages: | 6,417,278 |
Posted today: | 1 |