PDA

Ver la Versión Completa : crear varias tablas en word


emeritos
14-06-2022, 14:02:14
Buenas estoy haciendo desde delphi7 un word y debo de crear varias tablas independiente. Este es mi codigo:

Documento := ExtractFilePath( Application.ExeName ) + ficheropdf + '.docx';
Word.Connect;
Word.Documents.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam);
with Word do
Begin
with Selection do
Begin
with Sections.Item(1).Headers.Item(1).Range do
Begin
Font.Name := 'Arial';
Font.Bold := 1;
Font.Size := 14;
Font.Color := clRed;
Text := 'xxxxxxxxxxxxxxxxxxx ';
Paragraphs.Item(1).Alignment := 1; // centramos párrafo
End;


TypeText( #13 + #13);
Font.Name := 'Arial';
Font.Size := 14;
Font.Color := clBlack;
Font.Bold := 1;
TypeText( 'Formación NO Reglada');
Font.Color := clBlue;
Font.Size := 14;
Paragraphs.Item(1).Alignment := 1; // centramos párrafo

sw_filastotal := 5;

// Insertamos una tabla con fuente de color negro
Font.Color := clBlack;
with Tables.Add( Range, sw_filastotal, 3, EmptyParam, EmptyParam ) do
begin
// Borde la la tabla
Borders.Enable := 1;

// Títulos y ancho de las columnas de la tabla
Cell(1,1).Range.Text := 'xxxxxxxxx';
Cell(1,1).Width := 200;
Cell(1,1).RightPadding;

Cell(1,2).Range.Text := ' Horas ';
Cell(1,2).Width := 60;

Cell(1,3).Range.Text := ' Puntos ';
Cell(1,3).Width := 60;

Rows.Item(1).Shading.BackgroundPatternColor := clGreen; // fonfo verde
Rows.Item(1).Range.Font.Color := clYellow; // fuente amarilla

MQreglada.First;
While Not MQreglada.Eof do
Begin
// Anchura de las Celdas
Cell(sw_filas,1).Width := 200;
Cell(sw_filas,2).Width := 60;
Cell(sw_filas,3).Width := 60;

// Contenido
Cell(sw_filas,1).Range.Text := MQreglada['nombrereglada'];
Cell(sw_filas,2).Range.Text := MQreglada['horas'];
Cell(sw_filas,3).Range.Text := MQreglada['puntos'];;
sw_filas := sw_filas + 1;
MQreglada.Next;
End;
end;



End;
MQreglada.Close;

///// A partir de aqui me lo crea todo en la celda 1,1

TypeText( #13 + #13);
Font.Name := 'Arial';
Font.Size := 14;
Font.Color := clBlack;
Font.Bold := 1;
TypeText( 'dddddddddddddddddddddd');
Font.Color := clBlue;
Font.Size := 14;
with Tables.Add( Range, sw_filastotal, 3, EmptyParam, EmptyParam ) do
begin
// Borde la la tabla
Borders.Enable := 1;

// Títulos y ancho de las columnas de la tabla
Cell(1,1).Range.Text := 'hhhhhhhhhhhhhhhhh';
Cell(1,1).Width := 100;
Cell(1,1).RightPadding;

Cell(1,2).Range.Text := ' Meses ';
Cell(1,2).Width := 60;

Cell(1,3).Range.Text := ' Puntos ';
Cell(1,3).Width := 60;

Rows.Item(1).Shading.BackgroundPatternColor := clGreen; // fonfo verde
Rows.Item(1).Range.Font.Color := clYellow; // fuente amarilla

MQexperiencia.First;
While Not MQexperiencia.Eof do
Begin
// Anchura de las Celdas
Cell(sw_filas,1).Width := 100;
Cell(sw_filas,2).Width := 60;
Cell(sw_filas,3).Width := 60;

// Contenido
Cell(sw_filas,1).Range.Text := MQexperiencia['nombreexperiencia'];
Cell(sw_filas,2).Range.Text := MQexperiencia['meses'];
Cell(sw_filas,3).Range.Text := MQexperiencia['puntos'];;
sw_filas := sw_filas + 1;
MQexperiencia.Next;
End;
end;
End;
MQexperiencia.Close;

End;
End;


// Grabar y cerra documento
Word.ActiveDocument.SaveAs( Documento,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam );
Word.Quit;
Word.Disconnect;
Word.Free;


Lo primero es que la primera tabla me la crea bien y la segunda me la coloca en la celda (1,1) (junto tambien al su encabezado), de la primera tabla y no se distinguir entre la primera y la segunda aunque no es importante por que lo que quiero es crearla una debajo de la otra.

Gracias.