Página 2 de 4

gerar arquivos em word usando harbour

Enviado: 31 Mai 2013 14:34
por Pablo César
Fantastico !

Obrigado Hasse por compartilhar conosco !

:)Pos

gerar arquivos em word usando harbour

Enviado: 31 Mai 2013 19:47
por Hasse
Partindo de um Mestre considero esta avaliação como um grande elogio.

Obrigado.

gerar arquivos em word usando harbour

Enviado: 04 Jun 2013 16:54
por Amparo
ola amigos

Hasse, eu nao sei nem o que falar...

voce nao pode imaginar o quanto estou feliz em conseguir emitir um contrato em meu sistema feito em puro Harbour no formato do word, sao pessoa como voce o Pablo o Itamar o Rochinha e outros que nao me lembro o nome agora, mas que a cada dia merecem aplausos e mais aplausos.

muito mais muito obrigado mesmo, espero um dia por estar a altura de voces e poder ajudar outros que tambem necessitam.

abraços
Amparo.

gerar arquivos em word usando harbour

Enviado: 05 Jun 2013 19:12
por Hasse
Fico especial e duplamente satisfeito com esta tua vibrante satisfação e alegria.

Aqui estaremos sempre às ordens para nos ajudarmos mutuamente. Fui muito auxiliado no meu início com o xHarbour, e agora procuro retribuir da melhor forma possível.

E ainda preciso de auxílio, agora que estou dando os primeiros passos na MiniGUI. Ou seja, sempre aprendendo...

gerar arquivos em word usando harbour

Enviado: 02 Jul 2013 11:37
por Amparo
ola pessoal

tudo bem com vcs...

preciso novamente da ajuda dos colenas, esta aparecendo um erro ao abrir e imprimir um arquivo RTF no word

abaixo a linha completa da procedure

Código: Selecionar todos

Procedure IMPRIME_WORD( CARQ )
Local oWord

oWord:=TOleAuto():New( "Word.Application" )
oWord:Documents:Open( CARQ )
oWord:WindowState := 1
oWord:Visible := .t.
oWord:PrintOut()   //PARA IMPRIMIR DIRETO

Return
e aparece o seguinte erro:
Erro TOleAuto/-1 0x80080005: TOLEAUTO:NEW
Erro DOS nÆo dispon¡vel

se eu der dois cliques no arquivo RTF ele abre o WORD com todos os dados corretamente, ja tentei alterar a linha do prg colocando assim:
oWord:=TOleAuto():New( "WinWord.Application" )

ai da outro erro:
Erro TOleAuto/-1 CO_E_CLASSSTRING: TOLEAUTO:NEW
Erro DOS nÆo dispon¡vel

alguem tem ideia do que pode ser?

gerar arquivos em word usando harbour

Enviado: 02 Jul 2013 16:27
por rochinha
Amiguinhos,

Vale a pena relembrar MERGE - Colagem de dados via Command Line.

No caso do acesso via OLE cabe-se usar CreateObject( "Word.Application" ) ou Win_CreateObject( "Word.Application" ) no lugar de TOLEAuto():New( "Word.Application" ).

Quando sabemos qual a versão de nossos Offices podemos reforçar a forma de chamada assim:

( "Word.Application.8" ) // Para versão 8
( "Word.Application.10" ) // Para versão 10
( "Word.Application.11" ) // Para versão 11

etc.

gerar arquivos em word usando harbour

Enviado: 01 Nov 2019 12:53
por cjp
Pessoal, estou precisando criar um arquivo do Word por meio de minha aplicação em Harbour. Pesquisando no fórum, achei este post. Testei os exemplos acima, mas não consegui nem compilá-los.
Agradeceria se alguém poderia dar dicas para um iniciante. É um arquivo simples, só com texto, mas preciso de mínimas formatações do Word, nada complexo.
Qualquer ajuda é bem vinda.

gerar arquivos em word usando harbour

Enviado: 01 Nov 2019 13:27
por sygecom
Inacio,
Post os erros que está dando ao compilar

gerar arquivos em word usando harbour

Enviado: 02 Nov 2019 10:30
por cjp
Primeiro está dando erro nesta linha:

Código: Selecionar todos

#include 'winpar.ch' -> Define for Windows variables wd...
Imagino que esteja faltando alguma lib.

Daí eu comentei essa linha, só que daí dá vários erros de compilação, especialmente nas linhas que têm:

Código: Selecionar todos

otb2:Cell(1, 1) := __text
Agradeço toda ajuda.

gerar arquivos em word usando harbour

Enviado: 02 Nov 2019 19:07
por JoséQuintas
cjp escreveu:Imagino que esteja faltando alguma lib.

Código: Selecionar todos

#include "winpar.ch" 
Isso é pra incluir dentro do PRG o arquivo winpar.ch
Se está dando erro, é porque não existe o arquivo winpar.ch
Se isso vém de uma LIB ou não, ou se vai precisar de mais coisas, aí já é outra história.

Ou se está do jeito que escreveu.... talvez esteja escrito errado.

gerar arquivos em word usando harbour

Enviado: 03 Nov 2019 01:11
por cjp
De fato, o arquivo winpar.ch não existe no meu computador.
Se ele é de alguma lib, qual seria? E como a obtenho?
Se estiver escrito errado, não fui eu que escrevi, só copiei o que está neste post.

gerar arquivos em word usando harbour

Enviado: 03 Nov 2019 09:56
por JoséQuintas

Código: Selecionar todos

#include 'winpar.ch' -> Define for Windows variables wd...
É que do jeito acima, nem sei se funciona

Se não tiver outro jeito, na Microsoft tem todos as constantes/#defines
Mas é uma lista gigantesca, milhares.
Pode compilar usando -w3 -es2 e digitar somente o que o fonte precisar.

Seria interessante, talvez, alterar pra "office.ch" e deixar tudo em maiúsculas como é o padrão do Harbour/Clipper.

https://docs.microsoft.com/pt-br/office ... dlinestyle

por exemplo, alguns dessa página:

Código: Selecionar todos

#define WDLINESTYLEDASHDOT 0,5
#define WDLINESTYLEDASHDOTDOT 6
Se não encontrar o tal winpar.ch, o jeito vai ser digitar.

Ou verifique nas LIBs GUI se tem algum exemplo, e se tem arquivo equivalente.
Ou algum kit SDK da Microsoft que tenha isso.

gerar arquivos em word usando harbour

Enviado: 03 Nov 2019 23:45
por sygecom
cjp escreveu:Primeiro está dando erro nesta linha:

Código: Selecionar todos

#include 'winpar.ch' -> Define for Windows variables wd...
Imagino que esteja faltando alguma lib.

Daí eu comentei essa linha, só que daí dá vários erros de compilação, especialmente nas linhas que têm:

Código: Selecionar todos

otb2:Cell(1, 1) := __text
Agradeço toda ajuda.
Olhei todos os post aqui não tem nenhum com: #include 'winpar.ch', de onde você tirou isso ? por que colocou no seu código ? Post o exemplo completo que está tentando compilar.

gerar arquivos em word usando harbour

Enviado: 04 Nov 2019 01:20
por cjp
Segue meu código completo, exatamente como retirei do post acima:

Código: Selecionar todos

function main

*Hi all , after a lot of try and fail I got what is expected.
*It´s VB problem related to RANGE and SELECTION.

*The code that works :

*#include 'winpar.ch' -> Define for Windows variables wd...

table_form()


******************************************************************************
function table_form()
******************************************************************************
* Parameter vtbl -> order data array para vtbl
LOCAL oWord,__text

*TRY
   oWord := CreateObject( "Word.Application" )
*CATCH
*   Alert( "ERROR! Word not avalable. [" + Ole2TxtError()+ "]" )
*   retu NIL
*END

oWord:Visible := .T.

* Creating new Doc

odoc := oWord:Documents:Add()

* DOC Setup
*-----------------------------------------------------------------
*odoc:PageSetup:Orientation(wdOrientLandscape)

* Don't know why but Word Function CentimetersToPoints cause LINKER error ?!

*odoc:PageSetup:TopMargin := oWord:CentimetersToPoints(2.5)

odoc:PageSetup:TopMargin := 80   //  points
odoc:PageSetup:BottomMargin := 60
odoc:PageSetup:LeftMargin := 60
odoc:PageSetup:RightMargin := 40
*odoc:PageSetup:Gutter := 0
odoc:PageSetup:HeaderDistance := 40
odoc:PageSetup:FooterDistance := 40
*odoc:PageSetup:PageWidth := 21
*odoc:PageSetup:PageHeight := 29.7
*odoc:PageSetup:VerticalAlignment := wdAlignVerticalTop
* DOC Setup
*-----------------------------------------------------------------

* Header
*--------------------------------------------------------------------
odoc:ActiveWindow:ActivePane:View:SeekView(wdSeekCurrentPageHeader)
odoc:Select()
oWord:Selection:ParagraphFormat:Alignment := wdAlignParagraphCenter
oWord:Selection:Font:Name := "Arial"
oWord:Selection:Font:Bold := wdToggle
__text := hb_oemtoansi("Order Confirmation")
oWord:Selection:TypeText(__text)
* Header
*--------------------------------------------------------------------

* Footer
*--------------------------------------------------------------------
odoc:ActiveWindow:ActivePane:View:SeekView(wdSeekCurrentPageFooter)
odoc:Select()
oWord:Selection:ParagraphFormat:Alignment := wdAlignParagraphLeft
oWord:Selection:Font:Name := "Arial"
oWord:Selection:Font:Bold := wdToggle
oWord:Selection:Font:Size := 6
*                           Order number
*
__text := hb_oemtoansi("PD"+ pdv->codigo + ".DOC")
oWord:Selection:TypeText(__text)

* Blank Lines
oWord:Selection:TypeParagraph()
oWord:Selection:TypeParagraph()

oWord:Selection:ParagraphFormat:Alignment := wdAlignParagraphCenter
oWord:Selection:Font:Name := "Arial"
oWord:Selection:Font:Bold := wdToggle
oWord:Selection:Font:Size := 8
__auto := 'AUTOTEXT  "P gina X de Y" '
__auto := hb_oemtoansi(__auto)
oWord:Selection:Fields:Add(oWord:Selection:Range, -1, __auto, .T.)
* Footer
*--------------------------------------------------------------------

* Return Active Doc
*---------------------------------------------------------
odoc:ActiveWindow:ActivePane:View:SeekView(wdSeekMainDocument)

* First Paragraph , just to assign a range for table 1

opr1 := odoc:Paragraphs:Add()  //  paragrafo 1 para Tab1
rng1 := opr1:Range
otb1 := odoc:Tables:Add(rng1, 3, 2)

* Tab1 setup

otb1:Borders:OutsideLineStyle := wdLineStyleSingle
otb1:Borders:InsideLineStyle  := wdLineStyleNone
otb1:Select()
oWord:Selection:Cells:VerticalAlignment := wdCellAlignVerticalCenter

* Tab1 rows and cols setup
otb1:Rows:Item(1):Height := 18
otb1:Rows:Item(2):Height := 12
otb1:Rows:Item(3):Height := 12

otb1:Columns:Item(1):PreferredWidth := 350
otb1:Columns:Item(2):PreferredWidth := 100

* Fill the cells
__text := 'ACME INC.' + ' - '

__text += 'Pedido : ' + alltrim(pdv->codigo)
otb1:Cell(1, 1):Range:Font:Name := "Arial"
otb1:Cell(1, 1):Range:Font:Size := 10
otb1:Cell(1, 1):Range:Font:Bold := wdToggle
*otb1:Cell(1, 1) := __text
otb1:Cell(1, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

__text := 'Data : ' + dtoc(pdv->dtinic)
otb1:Cell(1, 2):Range:Font:Name := "Arial"
otb1:Cell(1, 2):Range:Font:Size := 10
otb1:Cell(1, 2):Range:Font:Bold := wdToggle
*otb1:Cell(1, 2) := __text
otb1:Cell(1, 2):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

otb1:Cell(1, 2):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

__text := alltrim(cad->end) + ' - ' + alltrim(cad->bai)
__text += ' , ' + alltrim(cad->cid) + ' , ' + cad->uf
__text += ' - CEP : ' + alltrim(cad->cep)
otb1:Cell(2, 1):Range:Font:Name := "Arial"
otb1:Cell(2, 1):Range:Font:Size := 9
*otb1:Cell(2, 1) := __text
otb1:Cell(2, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

__text := 'Resp. LYC : Caio'
otb1:Cell(2, 2):Range:Font:Name := "Arial"
otb1:Cell(2, 2):Range:Font:Size := 9
otb1:Cell(2, 2):Range:Font:Bold := wdToggle
*otb1:Cell(2, 2) := __text
otb1:Cell(2, 2):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

__text := 'Tel. / Fax : ' + alltrim(cad->fone1) + ' / ' + alltrim(cad->fone2)
otb1:Cell(3, 1):Range:Font:Name := "Arial"
otb1:Cell(3, 1):Range:Font:Size := 9
*otb1:Cell(3, 1) := __text
otb1:Cell(2, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

otb1:Cell(3, 2):Range:Select()
oWord:Selection:Collapse(wdCollapseEnd)
* Closing Tab1 range , selection

* Blank Line

opr2 := odoc:Paragraphs:Add()  //  paragrafo 2
rng2 := opr2:Range
rng2:Select()
oWord:Selection:Collapse(wdCollapseEnd)

* Client Data

wlixo:=cli->(at_seek(pdv->codimp,.f.))
opr3 := odoc:Paragraphs:Add()  //  paragrafo 3 , Tab2
rng3 := opr3:Range

otb2 := odoc:Tables:Add(rng3, 3, 2)
otb2:Borders:OutsideLineStyle := wdLineStyleSingle
otb2:Borders:InsideLineStyle := wdLineStyleNone

otb2:Select()
oWord:Selection:Cells:VerticalAlignment := wdCellAlignVerticalCenter

otb2:Rows:Item(1):Height := 18
otb2:Rows:Item(2):Height := 12
otb2:Rows:Item(3):Height := 12

otb2:Columns:Item(1):PreferredWidth := 50
otb2:Columns:Item(2):PreferredWidth := 400

__text := 'Cliente : '

otb2:Cell(1, 1):Range:Font:Name := "Arial"
otb2:Cell(1, 1):Range:Font:Size := 10
*otb2:Cell(1, 1) := __text
otb2:Cell(1, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

__text := alltrim(cli->nome)
otb2:Cell(1, 2):Range:Font:Name := "Arial"
otb2:Cell(1, 2):Range:Font:Size := 10
*otb2:Cell(1, 2) := __text
otb2:Cell(1, 2):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

__text := ''

otb2:Cell(2, 1):Range:Font:Name := "Arial"
otb2:Cell(2, 1):Range:Font:Size := 10

*otb2:Cell(2, 1) := __text
otb2:Cell(2, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

__text := alltrim(cli->end) + ' - ' + alltrim(cli->bai)

__text += ' , ' + alltrim(cli->cid) + ' , ' + cli->uf
__text += ' - CEP : ' + alltrim(cli->cep)
otb2:Cell(2, 2):Range:Font:Name := "Arial"
otb2:Cell(2, 2):Range:Font:Size := 8
*otb2:Cell(2, 2) := __text
otb2:Cell(2, 2):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

__text := 'Contato : '

otb2:Cell(3, 1):Range:Font:Name := "Arial"
otb2:Cell(3, 1):Range:Font:Size := 8
otb2:Cell(3, 1) := __text
otb2:Cell(3, 1):Range:Select()
oWord:Selection:MoveRight(wdCell,1)

__text := alltrim(cli->contato)
otb2:Cell(3, 2):Range:Font:Name := "Arial"
otb2:Cell(3, 2):Range:Font:Size := 8
otb2:Cell(3, 2) := __text
otb2:Cell(3, 2):Range:Select()
oWord:Selection:Collapse(wdCollapseEnd)

* Blank Line

opr4 := odoc:Paragraphs:Add()  //  paragrafo 4
rng4 := opr4:Range
rng4:Select()
oWord:Selection:Collapse(wdCollapseEnd)

* Order Table Instruction and Button

opr5 := odoc:Paragraphs:Add()  //  paragrafo 5
rng5 := opr5:Range

otb3 := odoc:Tables:Add(rng5, 1, 2)
otb3:Select()
oWord:Selection:Cells:VerticalAlignment := wdCellAlignVerticalCenter

otb3:Borders:OutsideLineStyle := wdLineStyleNone
otb3:Borders:InsideLineStyle := wdLineStyleNone

otb3:Rows:Item(1):Height := 16

otb3:Columns:Item(1):PreferredWidth := 350
otb3:Columns:Item(2):PreferredWidth := 100

__mens := 'Eventuais altera‡äes de quantidades podem ser feitas na Col. "Qtde. Alt.".'
__mens += chr(13) + chr(10)
__mens += 'Em caso de altera‡äes, para atualizar Tab. Pedido basta clicar botÆo "Atualizar Pedido".'
__mens := hb_oemtoansi(__mens)
otb3:Cell(1, 1):Range:Font:Name := "Arial"
otb3:Cell(1, 1):Range:Font:Size := 8
otb3:Cell(1, 1):Range:Font:Bold := wdToggle
otb3:Cell(1, 1) := __mens
otb3:Cell(1, 1):Range:Select()
oWord:Selection:MoveLeft(wdCell,1)

* Command Button Def.
rngb := otb3:Cell(1, 2):Range
rngb:Select()
oWord:Selection:ParagraphFormat:Alignment := wdAlignParagraphRight

obot := rngb:InLineshapes:AddOLEControl("Forms.CommandButton.1")

ocmd := obot:OLEFormat:Object
ocmd:Font:Name := "Verdana"
ocmd:Font:Size := 9
ocmd:Caption := " Atualizar Pedido "
ocmd:ForeColor := "&H808000"
ocmd:BackColor := "&HC0FFFF"
ocmd:AutoSize := .t.

* Command Button "on click" Sub

scode := 'Private Sub CommandButton1_Click()' + chr(13) + chr(10)
scode += 'Word.ActiveDocument.UnProtect("hu")' + chr(13) + chr(10)
scode += 'Word.ActiveDocument.Tables.Item(4).Columns.Item(7).Select' +

chr(13) + chr(10)
scode += 'Selection.Fields.Update' + chr(13) + chr(10)
scode += 'Selection.Collapse(wdCollapseEnd)' + chr(13) + chr(10)
scode += 'Word.ActiveDocument.Protect Type:=
wdAllowOnlyFormFields,NoReset:=True,Password:="hu"' + chr(13) + chr(10)
scode += 'End Sub'

scode := hb_oemtoansi(scode)
odoc:VBProject:VBComponents:Item(1):CodeModule:AddFromString(scode)
oWord:Selection:Collapse(wdCollapseEnd)

* Linha em branco
opr6 := odoc:Paragraphs:Add()  //  paragrafo 6
rng6 := opr6:Range
rng6:Select()
oWord:Selection:Collapse(wdCollapseEnd)

* Order Table Header array
vcab := {}
aadd(vcab,'Codigo Mercado')  //  esquerda
aadd(vcab,'Marca')           //  centro
aadd(vcab,'FOB US$')         //  direita
aadd(vcab,'Qtde.')           //  direita
aadd(vcab,'Total US$')       //  direita
aadd(vcab,'Qtde. Alt.')      //  direita
aadd(vcab,'Total Alt. US$')  //  direita

* Order Table Def.
oprA := odoc:Paragraphs:Add()  //  paragrafo 10 , Tab3
rngA := oprA:Range

* Definicao linhas e colunas tabela
nrow := len(vtbl)
ncol := len(vcab)
*                            1 linha cab.
*
otb4 := odoc:Tables:Add(rngA,nrow+1,ncol)
otb4:Borders:OutsideLineStyle := wdLineStyleSingle
otb4:Borders:InsideLineStyle := wdLineStyleSingle
otb4:Select()
oWord:Selection:Cells:VerticalAlignment := wdCellAlignVerticalCenter

* Order Table Header

for ic = 1 to ncol
    __text := vcab[ic]
    otb4:Cell(1,ic):Range:Font:Name := "Arial"
    otb4:Cell(1,ic):Range:Font:Size := 9
    otb4:Cell(1,ic):Range:Font:Bold := wdToggle
    otb4:Cell(1,ic) := __text
    otb4:Columns:Item(ic):Select()
    if     ic = 1
           otb4:Columns:Item(ic):PreferredWidth := 100
           oWord:Selection:ParagraphFormat:Alignment :=
wdAlignParagraphLeft
    elseif ic = 2
           otb4:Columns:Item(ic):PreferredWidth := 50
           oWord:Selection:ParagraphFormat:Alignment :=
wdAlignParagraphCenter
    else
           otb4:Columns:Item(ic):PreferredWidth := 70
           oWord:Selection:ParagraphFormat:Alignment :=
wdAlignParagraphRight
    endi
    oWord:Selection:Collapse(wdCollapseEnd)
next

* Order Table

for i = 1 to nrow
    for j = 1 to ncol
        otb4:Cell(i+1,j):Range:Font:Name := "Courier New"
        otb4:Cell(i+1,j):Range:Font:Size := 8

        if j <= ncol-2
           __text := vtbl[i,j]
           otb4:Cell(i+1,j) := __text
        elseif j = ncol-1
           crng := otb4:Cell(i+1,j):Range

           odoc:FormFields:Add(crng,wdFieldFormTextInput)
        else
           formula := "="
           formula += "C" + alltrim(tran(i+1,'999'))
           formula += "*"
           formula += "F" + alltrim(tran(i+1,'999'))
           otb4:Cell(i+1,j):Formula(formula,"0,00")
        endi
    next
next
*
otb4:Cell(nrow+1,ncol):Range:Select()
oWord:Selection:Collapse(wdCollapseEnd)

oWord:ActiveDocument:Protect(wdAllowOnlyFormFields,.t.,"hu")
inkey(0)

odoc:SaveAS("C:\test\test.doc")

odoc:Close()
oWord:Quit()

return NIL

gerar arquivos em word usando harbour

Enviado: 04 Nov 2019 18:14
por JoséQuintas
Quando o Itamar postou o fonte, postou também a origem, o link no fórum do google.

Se é pra olhar como fica... melhor procurar outro exemplo.

Se realmente for mexer, pode usar o link de origem da mensagem e pedir o arquivo.