Ver Mensaje Individual
  #3  
Antiguo 06-06-2007
JulioGO JulioGO is offline
Miembro
 
Registrado: ago 2004
Posts: 94
Reputación: 20
JulioGO Va por buen camino
Question Talk con Word

Aqui esta el codigo.

Código:
procedure TdlgLRetenc.spComprobClick(Sender: TObject);
var
  Word: Variant;
  Documento: Variant;
//  i: smallint;
begin
  (* Creas un objeto Word *)
  try
    Word := CreateOleObject('Word.Application');
  except
    Application.MessageBox('No se puede puede conectar con MS (c) Word',
                           'Liquidación de Aportes y Retenciones', MB_OK + MB_ICONERROR);
    exit;
  end;
  dmMntPlan.ibqLRetenc.First;
  while not dmMntPlan.ibqLRetenc.Eof do
   begin
    if dmMntPlan.ibqLRetenc.FieldValues['ESTADO'] = 'S' then
     begin
      (* Añades un documento basado en la plantilla *)
      Word.Documents.Add('c:\sistemas\sisplani\RENTEC_27605.dot'); //Esto abre un documento por cada archivo
      Documento := Word.Documents.Item(1);

      (* Asignas valores a los campos *)
      Documento.Variables.Add('EJERCICIO', cVGPeriTra);
      Documento.Variables.Add('RAZON_SOCIAL', cVGrazsoc);
      Documento.Variables.Add('RUC', cvgNroRuc);
      Documento.Variables.Add('TRABAJ', dmMntPlan.ibqLRetenc.FieldValues['NOMBRES']);
      if Copy(ComboBox1.Items[ComboBox1.ItemIndex], 1, 2) = '02' then
        Documento.Variables.Add('TIPDOC', 'D.N.I.')
      else
        Documento.Variables.Add('TIPDOC', 'CUSSP');
      if Copy(ComboBox1.Items[ComboBox1.ItemIndex], 1, 2) = '02' then
        Documento.Variables.Add('SISPEN', 'S.N.P.')
      else
        Documento.Variables.Add('SISPEN', 'S.P.P. ' + ComboBox1.Items[ComboBox1.ItemIndex]);
      Documento.Variables.Add('NUMDOC', dmMntPlan.ibqLRetenc.FieldValues['DOCUM']);
      Documento.Variables.Add('TOTAL_RETENC', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['APTE_SNP'] +
                                              dmMntPlan.ibqLRetenc.FieldValues['APTE_SPP']));
      Documento.Variables.Add('TOTAL_REMUN', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['TOTAL_REMUN']));
      Documento.Variables.Add('APTE_SNP', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['APTE_SNP']));
      Documento.Variables.Add('APTE_SPP', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['APTE_SPP']));
      Documento.Variables.Add('COMISION', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['COMISION']));
      Documento.Variables.Add('PRIMA', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['PRIMA']));
      Documento.Variables.Add('CUENTA_INDIV', FormatFloat(',0.00', dmMntPlan.ibqLRetenc.FieldValues['INDIV']));
      //Documento.Fields.ToggleShowCodes;
      Documento.Fields.Update;
     end;
    dmMntPlan.ibqLRetenc.Next;
   end;
  Word.Visible := true;
end;
Responder Con Cita