Word ActiveX change text parameters Bold, Font...

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
Victorio
Posts: 620
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Word ActiveX change text parameters Bold, Font...

#1 Post by Victorio »

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.

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: Word ActiveX change text parameters Bold, Font...

#2 Post by Auge_Ohr »

not sure about Word but in Excel you have to set e.g. Color "before" fill Text

Code: Select all

oRange := oSheet:Range("A1:C1")
*oRange:Font:Color = -16777024
oRange:Font:Color = GraMakeRGBColor({255, 0, 0})-(256*256*256)
---

as i remember Tom have written something about "Word Replace" using "Find.Execute"
https://msdn.microsoft.com/de-de/vba/wo ... ethod-word
greetings by OHR
Jimmy

Victorio
Posts: 620
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Word ActiveX change text parameters Bold, Font...

#3 Post by Victorio »

I am not sure, in my example if good understand work only with bookmarks, but this changes to values from array.

other thing is, I am not sure if it is good way bind my app with MS office, because not everybody have installed it, some users may have only open office or other software
better way (but with more work on it) is include internal functions to create document in own application and no need other support software.

Wolfgang Ciriack
Posts: 478
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Word ActiveX change text parameters Bold, Font...

#4 Post by Wolfgang Ciriack »

If you decide to make your own, have a look at the ActiveX TxControl https://www.textcontrol.com/.
_______________________
Best Regards
Wolfgang

Post Reply