Fórum Posicionar Tabela no Word via Delphi #403509
21/06/2011
0
procedure TFrmOrcamento.GerarOrcamentoTelesegura;var winWord, docs, doc, tabela1: variant; linha: Integer; total: real;begin
total:=0;
try WinWord:= CreateOleObject('Word.Application'); except on E: Exception do begin E.Message :='Instale o Microsoft Word!'; raise; end; end; WinWord.Visible := true; Docs := WinWord.Documents;
if fileExists(ExtractFileDir(Application.ExeName) + '\Documentos\OrcamentoTelesegura2.doc')=true then deletefile(ExtractFileDir(Application.ExeName) + '\Documentos\OrcamentoTelesegura2.doc'); CopyFile(Pchar(ExtractFileDir(Application.ExeName) +'\Documentos\OrcamentoTelesegura.doc'), Pchar(ExtractFileDir(Application.ExeName) +'\Documentos\OrcamentoTelesegura2.doc'), True);
Doc := Docs.Open(ExtractFileDir(Application.ExeName) +'\Documentos\OrcamentoTelesegura2.doc'); Doc.Content.Find.Execute(FindText :='%01%', ReplaceWith := DmTabelas.CdsOrcamentoNOME.AsString); Doc.Content.Find.Execute(FindText :='%02%', ReplaceWith := DmTabelas.CdsOrcamentoENDERECOORCAMENTO.AsString+','+DmTabelas.CdsOrcamentoNUMERO.AsString); Doc.Content.Find.Execute(FindText :='%03%', ReplaceWith := DmTabelas.CdsOrcamentoBAIRROORCAMENTO.AsString); Doc.Content.Find.Execute(FindText :='%04%', ReplaceWith := DmTabelas.CdsOrcamentoTELEFONEORCAMENTO.DisplayText); Doc.Content.Find.Execute(FindText :='%05%', ReplaceWith := DmTabelas.CdsOrcamentoEMAILORCAMENTO.AsString); Doc.Content.Find.Execute(FindText :='%07%', ReplaceWith := DmTabelas.CdsOrcamentoCONDICOESPGTO.AsString); Doc.Content.Find.Execute(FindText :='%08%', ReplaceWith := DmTabelas.CdsOrcamentoOBS.AsString);
//TABELA 1
Tabela1 := Doc.Tables.Add(Range := Doc.Range(Start := 290, End := 290), NumRows := DmTabelas.CdsItensOrcamento.RecordCount + 1, NumColumns := 5); Linha:=1; Tabela1.Cell(Row := Linha, Column := 1).Range.InsertAfter('Qtde'); Tabela1.Cell(Row := Linha, Column := 2).Range.InsertAfter('Descrição'); Tabela1.Cell(Row := Linha, Column := 3).Range.InsertAfter('Unidade'); Tabela1.Cell(Row := Linha, Column := 4).Range.InsertAfter('Valor Unitário'); Tabela1.Cell(Row := Linha, Column := 5).Range.InsertAfter('Sub-Total'); Tabela1.AutoFormat(Format := 16, ApplyBorders := False);
Linha := 2; DmTabelas.CdsItensOrcamento.First;
while not DmTabelas.CdsItensOrcamento.Eof do begin Tabela1.Cell(Row := Linha, Column := 1).Range.InsertAfter(Text := FormatFloat('###,###,##0.00',DmTabelas.CdsItensOrcamentoQTD.AsFloat)); Tabela1.Cell(Row := Linha, Column := 2).Range.InsertAfter(Text := DmTabelas.CdsItensOrcamentoDESCRICAO.AsString); Tabela1.Cell(Row := Linha, Column := 3).Range.InsertAfter(Text := DmTabelas.CdsItensOrcamentoUNIDADE.AsString); Tabela1.Cell(Row := Linha, Column := 4).Range.InsertAfter(Text := FormatFloat('R$ ###,###,##0.00',DmTabelas.CdsItensOrcamentoPRECO.AsFloat)); Tabela1.Cell(Row := Linha, Column := 5).Range.InsertAfter(Text := FormatFloat('R$ ###,###,##0.00',Dmtabelas.CdsItensOrcamentoPRECO.Asfloat*DmTabelas.CdsItensOrcamentoQTD.AsFloat)); Linha := Linha + 1; DmTabelas.CdsItensOrcamento.Next; Tabela1.AutoFormat(Format := 16, ApplyBorders := False); total:=total+(Dmtabelas.CdsItensOrcamentoPRECO.Asfloat * DmTabelas.CdsItensOrcamentoQTD.AsFloat); end;
Doc.Content.Find.Execute(FindText :='%06%', ReplaceWith := FormatFloat('R$ ###,###,##0.00',DmTabelas.CdsorcamentoTOTAL.AsFloat));end;
Claudio Junior
Curtir tópico
+ 0Posts
25/06/2011
Anderson Nunes
Gostei + 0
05/05/2013
José
Gostei + 0
06/05/2013
Claudio Junior
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)