Merge cells in the Word Table with Delphi

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.