31 Mai 2013 14:34
31 Mai 2013 19:47
04 Jun 2013 16:54
05 Jun 2013 19:12
02 Jul 2013 11:37
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
02 Jul 2013 16:27
01 Nov 2019 12:53
01 Nov 2019 13:27
02 Nov 2019 10:30
#include 'winpar.ch' -> Define for Windows variables wd...
otb2:Cell(1, 1) := __text
02 Nov 2019 19:07
cjp escreveu:Imagino que esteja faltando alguma lib.
#include "winpar.ch"
03 Nov 2019 01:11
03 Nov 2019 09:56
#include 'winpar.ch' -> Define for Windows variables wd...
#define WDLINESTYLEDASHDOT 0,5
#define WDLINESTYLEDASHDOTDOT 6
03 Nov 2019 23:45
cjp escreveu:Primeiro está dando erro nesta linha:
- Código:
#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:
otb2:Cell(1, 1) := __text
Agradeço toda ajuda.
04 Nov 2019 01:20
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
04 Nov 2019 18:14