Quantcast
Channel: Net Express / Server Express - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 375

Integração NetExpress 3.1 com MS Word

$
0
0

Prezados Amigos,

Usei este programa como exemplo para gerar documentos no Microsoft Word:

$set ooctrl(+P) ooctrl(+Q)
*copy "word.if". *> Word vocavularies
*copy "excel.if". *> Excel vocabularies
program-id. WORDAPI.
special-names. call-convention 2 is WinApi.

Class-Control.
*-------------

WordApp is class "$OLE$word.application". *> Word 97

Working-Storage Section.
*------------------------------
77 j pic 9(003).
77 k pic 9(003).
77 wChar pic X(001).

01 WordServer object reference value null.
01 theDocuments object reference value null.
01 theDocument object reference value null.
01 theSelection object reference value null.
01 theReplacement object reference value null.
01 theParagraphs object reference value null.
01 theParagraph object reference value null.
01 theRange object reference value null.
01 theFind object reference value null.

01 wText pic X(255).

01 found pic x comp-5.
88 found-True value 45.
88 found-False value 48.

01 Program-Flags pic 9(2) comp-5 value 1.
88 New-Instance value 1 false 0.

Linkage Section.
*----------------
01 wrdParam.
05 wrdOperation pic x(008).
05 wrdFileName pic x(255).
05 wrdText pic x(255).
05 wrdChange2 pic x(255).
05 wrdSearchStatus pic x(002).
05 wordVisible pic s9(001).
05 wordSaveMode pic s9(001).

Procedure Division Using wrdParam.
******************************************************************
*
* If New-Instance
* Perform New-Set-Instance
* End-if

Evaluate wrdOperation
When 'Create'
Perform Create-Aplication
When 'Open'
Perform File-Open
When 'Delete'
Perform Delete-Selection
When 'Insert'
Perform Insert-Text
When 'Find'
Perform Find-Text
When 'Replace'
Perform Replace-Text
When 'FReplace'
* Perform Find-and-Replace-Text
Perform Find-Text
Perform Replace-Text
When 'Preview'
Perform Print-Preview
When 'Print'
Perform Print-Document
When 'Quit'
Perform Quit-Set-Instance
End-Evaluate

Exit Program
.
*----------------------------------------------------------------
Create-Aplication Section.

*> Criar uma instancia do Word
Invoke wordapp "new" Returning wordServer

*> Pega o objeto de coleção Word documents
Invoke wordServer "getDocuments" Returning theDocuments

*> Seta se o Word será visualizado
invoke wordServer "SetVisible" using by value wordVisible
.
*----------------------------------------------------------------
File-Open Section.

*> Abre o arquivo em wrdFileName
Invoke theDocuments "Open" Using wrdFileName

*> Pega o documento ativo
Invoke wordServer "getActiveDocument" Returning theDocument
.
*----------------------------------------------------------------
Delete-Selection Section.

* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "Delete"

*> Seleciona o texto encontrado
invoke theRange "select"

*> 'CUTila' o texto encontrado
invoke theRange "Cut"
.
*----------------------------------------------------------------
Insert-Text Section.

* Move wrdChange2 to wText

* Perform Null-Terminate-Routine
* Move wText to wrdChange2
* invoke wordServer "getSelection" returning theSelection
* invoke theSelection "InsertAfter" using by content wrdChange2

*> Insere o texto
invoke theRange "InsertAfter" using by content wrdChange2
.
*----------------------------------------------------------------
Find-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" returning theFind

*> A procura será para frente
Invoke theFind "setForward" using by value 1

*> A busca sera pelo conteudo de wrdText
Invoke theFind "setText" using by content wrdText

*> Procurar
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Find-and-Replace-Text Section.

Move "23" to wrdSearchStatus
Move wrdText to wText

Perform Null-Terminate-Routine

Move wText to wrdText
Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2

*> Pega o objeto Range
Invoke theDocument "getContent" returning theRange

*> Pega o objecto Find
Invoke theRange "getFind" Returning theFind

*> A procura será para frente
Invoke theFind "getReplacement" Returning theReplacement

Invoke theFind "setForward" Using by value 1
*> A busca sera pelo conteudo de wrdText

Invoke theFind "setText" Using by content wrdText
Invoke theReplacement "setText" Using by content wrdChange2

*> Procurar
* Invoke theFind "setReplace" Using by value 1
Invoke theFind "execute"

*> Encontrou ?
Invoke theFind "getFound" returning found

*> Se encontrou...
if found-True
move "00" to wrdSearchStatus
end-if
.
*----------------------------------------------------------------
Replace-Text Section.

Move wrdChange2 to wText

Perform Null-Terminate-Routine

Move wText to wrdChange2
subtract 01 from k

*> Seleciona o texto encontrado
invoke theRange "select"

*> Finalmente, muda o texto encontrado (wrdText)
*> para o desejado
invoke theRange "Cut"
move 00 to j
invoke theRange "InsertAfter" using " "
perform until j = k
add 01 to j
move wrdChange2(j:1) to wChar
invoke theRange "InsertAfter" using by content wChar
end-perform

*> Não preciso mais dos objetos Find e Range
Invoke theFind "finalize" returning theFind
Invoke theRange "finalize" returning theRange
.
*----------------------------------------------------------------
Print-Preview Section.

invoke theDocument "PrintPreview"
.
*----------------------------------------------------------------
Print-Document Section.

invoke theDocument "PrintOut" using by value 0
.
*----------------------------------------------------------------
New-Set-Instance Section.

set New-Instance to false
.
*----------------------------------------------------------------
Null-Terminate-Routine Section.

move length of wText to j

perform varying k from j by -1
until k = 0

if wText(k:1) not = spaces and not = X"00"
add 01 to k
move x"00" to wText(k:1)
exit section
end-if

end-perform

move x"00" to wText(j:1)
.
*----------------------------------------------------------------
Size-Of-String Section.

move length of wText to j

perform varying k from j by -1
until k = 0
or wtext(k:1) not = spaces and x"00"
end-perform
.
*----------------------------------------------------------------
Quit-Set-Instance Section.

*> Fechar o arquivo sem salvando-o
if wordSaveMode = 0
Invoke theDocument "Close" Using by value 0
else
if wordSaveMode = -1
Invoke theDocument "Close" Using by value -1
end-if
end-if

*> Finalizar o objecto de coleção Documents
Invoke theDocuments "finalize" Returning theDocuments

*> Tell Word to quit (it won't shut down otherwise)
Invoke wordServer "quit"

*> Finalizar o Word
Invoke wordServer "finalize" Returning wordServer
.

1 - Como descubro todos os métodos da classe wordapp ?

2 - Onde encontro o arquivo "word.if" , definido no inicio do programa ?

Atenciosamente

Rogerio Barbosa Ferreira


Viewing all articles
Browse latest Browse all 375

Trending Articles