Merge cells in the Word Table with Delphi
// Merge the cells in the Word Table
Procedure mergewordcell;
VaR wordapp: twordapplication;
Worddoc: tworddocument;
Dockers, ofilename, cfcversions, oreadonly, addtorctfiles, pswdocument,
Pswtemplate, orevert, wpswdocument, wpswtemplate, oformat: olevariant;
I, irow, icol: integer;
Mycell: cell;
Myrow: row;
Begin
Memo1.lines. Clear;
// ===== Create an object ====
If not assigned (wordapp) then
Begin
Wordapp: = twordapplication. Create (NiL );
Wordapp. Visible: = false;
End;
If not assigned (worddoc) then
Worddoc: = tworddocument. Create (NiL );
Try
Docsag: = 1;
Ofilename: = 'd: est.doc ';
Oreadonly: = true;
Cfcversions: = emptyparam;
Addtorctfiles: = emptyparam;
Pswdocument: = emptyparam;
Pswtemplate: = emptyparam;
Orevert: = emptyparam;
Wpswdocument: = emptyparam;
Wpswtemplate: = emptyparam;
Oformat: = emptyparam;
// ===== Open the file =====
Wordapp. Documents. Open (ofilename, cfcversions, oreadonly, addtorctfiles,
Pswdocument, pswtemplate, orevert, wpswdocument, wpswtemplate, oformat );
// ===== Associated file ====
Worddoc. connectto (wordapp. Documents. Item (Dockers ));
// merge the first and second columns
istart: = worddoc. tables. item (I ). cell (1, 1 ). range. start;
mycol: = worddoc. tables. item (I ). columns. item (2);
iend: = mycol. cells. item (mycol. cells. count ). range. end _;
myrange: = worddoc. range;
myrange. start: = istart;
myrange. end _: = iend;
myrange. cells. merge;
finally
if assigned (worddoc) Then // ====== close the file =====< br> begin
worddoc. close;
worddoc. disconnect;
worddoc. destroy;
worddoc: = nil;
end;
if assigned (wordapp) then // ====== disable word =====< br> begin
wordapp. quit;
wordapp. disconnect;
wordapp. destroy;
wordapp: = nil;
end;