Ver Mensaje Individual
  #4  
Antiguo 24-06-2011
toni.vi toni.vi is offline
Miembro
 
Registrado: may 2003
Ubicación: Sant Fost(Barcelona)
Posts: 102
Reputación: 21
toni.vi Va por buen camino
la solución que he implementado es:
1.- Busco un marcador que es donde insertaré la tabla, posicionandome en este rango.
2.- Inserto la tabla.

Gracias por tu respuesta.

Toni

Código Delphi [-]
procedure InsertarTabla(DataSet: TDataSet; WordDoc: TWordDocument);
var
  WordTable: Table;
  ColIndexCount, RowCount, ColCount: Integer;
  RowIndex, ColIndex: Integer;

  Marcador : OleVariant;
begin
    RowCount := DataSet.RecordCount;
    ColCount := DataSet.Fields.Count;

    Marcador := 'TABLA_XXXX';
    //busco el marcador y si existe inserto la tabla
    if WordDocument1.Bookmarks.Exists(Marcador) then
    begin
      WordTable := WordDocument1.Tables.add(WordDocument1.Bookmarks.item(Marcador).Range, RowCount + 1, ColCount);

      //aqui hago la cabecera en negrita y en gris
      ColIndexCount := 0;
      for ColIndex := 1 to DataSet.Fields.Count do
      begin
        if DataSet.Fields[ColIndex - 1].Tag = 2 then
        begin
        ColIndexCount := ColindexCount + 1;
        WordTable.Cell(1, ColIndexCount).Range.Paragraphs.Borders.Enable := 1;
        WordTable.Cell(1, ColIndexCount).Range.Font.Bold                 := 1;
        WordTable.Cell(1, ColIndexCount).Range.Text                      := DataSet.Fields[ColIndex - 1].DisplayLabel;
        WordTable.Cell(1, ColIndexCount).Range.Paragraphs.Alignment      := wdAlignParagraphCenter;
        WordTable.Cell(1, ColIndexCount).Range.Cells.Shading.BackgroundPatternColorIndex:= wdGray25;
        end;
      end;

      RowIndex := 2;
      DataSet.First;
      while not DataSet.Eof do
      begin
        ColIndexCount := 0;
        for ColIndex := 1 to DataSet.Fields.Count do
        begin
          //los campos que su tag = 2 son los que quiero que se llenen en la tabla
          if DataSet.Fields[ColIndex - 1].Tag = 2 then
          begin
            ColIndexCount := ColindexCount + 1;
            WordTable.Cell(RowIndex, ColIndexCount).Range.Paragraphs.Borders.Enable := 1;
            WordTable.Cell(RowIndex, ColIndexCount).Range.Text                      := DataSet.Fields[ColIndex - 1].AsString;
          end;
        end;
        Inc(RowIndex);
        DataSet.Next;
      end;
    end;
end;
Responder Con Cita