Creo (no estoy demasiadao puesto en C++) que la traducción a Object Pascal sería:
Código Delphi
[-]
var
Word, doc, Selection, Font, Parrafo, rango, tablas, tabla, celda: Variant;
rows, cols, i, j: integer;
begin
word := Variant.CreateObject('Word.Application');
word.OlePropertySet( 'Visible', (Variant) true );
doc := word.OlePropertyGet('Documents');
if FileExists(ExtractFilePath(Application.ExeName)+ 'plantillas\plantilla.doc')) then
doc.OleFunction('Open', (ExtractFilePath(Application.ExeName)+ 'plantillas\plantilla.doc').c_str, Unassigned, true);
else
begin
MessageBox(Handle, 'El archivo no existe', 'Error' , MB_APPLMODAL or MB_OK or MB_ICONERROR);
word.OleProcedure('Quit');
Exit;
end;
Selection := word.OlePropertyGet('Selection');
Font := Selection.OlePropertyGet('Font');
Parrafo := Selection.OlePropertyGet('ParagraphFormat');
Parrafo.OlePropertySet('Alignment','1');
Font.OlePropertySet('Name','Verdana');
Font.OlePropertySet('Bold','1');
Font.OlePropertySet('Size','12');
Selection.OleProcedure('TypeText', 'TÍTULO'+#13#13#13);
Parrafo.OlePropertySet('Alignment','0');
Font.OlePropertySet('Size','10');
Selection.OleProcedure('TypeText', 'Nombre:'+#9);
Font.OlePropertySet('Bold','0');
Selection.OleProcedure('TypeText', (cboNombre.Text + #13).c_str);
Font.OlePropertySet('Bold','1');
Selection.OleProcedure('TypeText', 'Fecha:\t');
Font.OlePropertySet('Bold','0');
Selection.OleProcedure('TypeText', (txtFecha.Text + #13#13).c_str);
doc := word.OlePropertyGet('ActiveDocument');
rango := doc.OleFunction('Range');
rango.OleProcedure('Collapse', 0);
tablas := rango.OlePropertyGet('Tables');
rows := ListView1.Items.Count + 1;
cols := 2;
Parrafo.OlePropertySet('Alignment','0');
tabla := tablas.OleFunction('Add', rango, rows, cols);
celda := tabla.OleFunction('Cell', 1, 1);
celda.OlePropertyGet('Range').OleProcedure('InsertAfter', 'Producto');
celda := tabla.OleFunction('Cell', 1, 2);
celda.OlePropertyGet('Range').OleProcedure('InsertAfter', 'Cantidad');
i:=1;
while i < rows do
begin
j:=1;
while j<=cols
begin
if j=1
begin
celda := tabla.OleFunction('Cell', i+1, j);
celda.OlePropertyGet('Range').OleProcedure('InsertAfter', (ListView1.Items.Item[i-1].Caption).c_str);
end
else
begin
celda := tabla.OleFunction('Cell', i+1, j);
celda.OlePropertyGet('Range').OleProcedure('InsertAfter', (ListView1.Items.Item[i-1].SubItems[0][0]).c_str);
end;
Inc(j);
end;
Inc(i);
end;
Selection.OleProcedure('EndKey', 6);
Espero no haber cometido ningún error.
Saludos.