Word ActiveX change text parameters Bold, Font...
Posted: Fri Jan 19, 2018 11:45 am
Hi
I "play" with generate Word DOC documents programatically, with join with data source from my application.
I have pattern doc file, where are bookmarks, this I want change with own values from database.
This works, but I want controlling font, row spacing, bold, italic etc. to text replaced to bookmarks.
When I change font, or change to bold to entire document, work ok, but I do not know, how change parameters only for text replacing bookmarks :
Here is part of source :
// Create a Word ActiveX component
oWord := CreateObject("Word.Application")
oWord := oWord:dynamicCast(ActiveXObject())
oWord:Quit := {||lWordFinished := .T.}
oWord:visible := .T. // zobrazuje word dokument počas spracovania
lWordFinished := .f.
oWord:documents:open( cFile )
oDoc := oWord:ActiveDocument
oBM := oDoc:Bookmarks
* change font to whole document - this work good
oSelection:=oWord:Selection
oSelection:TypeText("Change font to Arial"+CRLF+CRLF) // toto doplní text do dokumentu na začiatok
oRange:=oSelection:Range
oRange:WholeStory()
oRange:Font:Name = "Courier"
* koniec pokusu zmeny fontu v celom dokumente
* pokusná zmena fontu na bold nie .T. , .F. ale 0 a 1 !!! ok funguje
* change to Bold to whole document - work fine
oRange:Font:Bold := 1 // to Bold
oRange:Font:Bold := 0 // and back to Normal
* Here call function, which change bookmark COMPANY with value from aData
* and here I want change for example to Arial and Bold
ReplaceBookmark(oBM , "COMPANY" , aData[1] )
...etc
RETURN .t.
* funkcia, ktorá vykoná samotné nahradenie konkrétnej bookmark/záložky
***********************************************
static FUNCTION ReplaceBookmark(oBM,cBM,cValue)
***********************************************
LOCAL lRet := oBM:Exists(cBM) // zistí, či bookmark existuje
LOCAL oF
* ak bookmark existuje
IF(lRet)
oF := oBM:Item(cBM) // načíta do premennej objekt pôvodnú hodnotu
oF:Range:Text := cValue // nahradí novým textom
* * *
* ??? can change also font , bold or some other parameter here ? only for cValue
* * *
oF:Destroy() // zatvorí objekt
ENDIF
RETURN(lRet)
Sorry, I am new in Active X , I just start to understand how this works.... I looked to Visual Basic manuals, Active X methods, etc. but I do not know, how this implement to application in Xbase++.
Helps me example in express++ , and also here , in forum, but do not have any complex example, how create more difficult reports.
I "play" with generate Word DOC documents programatically, with join with data source from my application.
I have pattern doc file, where are bookmarks, this I want change with own values from database.
This works, but I want controlling font, row spacing, bold, italic etc. to text replaced to bookmarks.
When I change font, or change to bold to entire document, work ok, but I do not know, how change parameters only for text replacing bookmarks :
Here is part of source :
// Create a Word ActiveX component
oWord := CreateObject("Word.Application")
oWord := oWord:dynamicCast(ActiveXObject())
oWord:Quit := {||lWordFinished := .T.}
oWord:visible := .T. // zobrazuje word dokument počas spracovania
lWordFinished := .f.
oWord:documents:open( cFile )
oDoc := oWord:ActiveDocument
oBM := oDoc:Bookmarks
* change font to whole document - this work good
oSelection:=oWord:Selection
oSelection:TypeText("Change font to Arial"+CRLF+CRLF) // toto doplní text do dokumentu na začiatok
oRange:=oSelection:Range
oRange:WholeStory()
oRange:Font:Name = "Courier"
* koniec pokusu zmeny fontu v celom dokumente
* pokusná zmena fontu na bold nie .T. , .F. ale 0 a 1 !!! ok funguje
* change to Bold to whole document - work fine
oRange:Font:Bold := 1 // to Bold
oRange:Font:Bold := 0 // and back to Normal
* Here call function, which change bookmark COMPANY with value from aData
* and here I want change for example to Arial and Bold
ReplaceBookmark(oBM , "COMPANY" , aData[1] )
...etc
RETURN .t.
* funkcia, ktorá vykoná samotné nahradenie konkrétnej bookmark/záložky
***********************************************
static FUNCTION ReplaceBookmark(oBM,cBM,cValue)
***********************************************
LOCAL lRet := oBM:Exists(cBM) // zistí, či bookmark existuje
LOCAL oF
* ak bookmark existuje
IF(lRet)
oF := oBM:Item(cBM) // načíta do premennej objekt pôvodnú hodnotu
oF:Range:Text := cValue // nahradí novým textom
* * *
* ??? can change also font , bold or some other parameter here ? only for cValue
* * *
oF:Destroy() // zatvorí objekt
ENDIF
RETURN(lRet)
Sorry, I am new in Active X , I just start to understand how this works.... I looked to Visual Basic manuals, Active X methods, etc. but I do not know, how this implement to application in Xbase++.
Helps me example in express++ , and also here , in forum, but do not have any complex example, how create more difficult reports.