// Obtain the data in the Word Table
Procedure getwordcellstr;
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:/test.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 ));
// Method (1) ==> rule table
For I: = 1 to worddoc. Tables. Count do // table I
Begin // row irow
For irow: = 1 to worddoc. Tables. Item (I). Rows. Count do
Begin // column icol
For icol: = 1 to worddoc. Tables. Item (I). Columns. Count do
Begin
Mycell: = worddoc. Tables. Item (I). Cell (irow, icol );
Memo1.lines. Add (mycell. range. Text );
End;
End;
End;
// Method (2) ==> irregular table: only when merging horizontally
For I: = 1 to worddoc. Tables. Count do // table I
Begin
For irow: = 1 to worddoc. Tables. Item (I). Rows. Count do
Begin
Myrow: = worddoc. Tables. Item (I). Rows. Item (irow); // line irow
For icol: = 1 to myrow. cells. Count do // column icol
Begin
Mycell: = myrow. cells. Item (icol );
Memo1.lines. Add (mycell. range. Text );
End;
End;
End;
// Method (3) ==> irregular: any table
For I: = 1 to worddoc. Tables. Count do // table I
Begin // number J of cells
For J: = 1 to worddoc. Tables. Item (I). range. cells. Count do
Begin
Mycell: = worddoc. Tables. Item (I). range. cells. Item (j );
Memo1.lines. Add (mycell. range. Text );
End;
End;
Finally
If assigned (worddoc) Then // ==== close the file ====
Begin
Worddoc. close;
Worddoc. Disconnect;
Worddoc. Destroy;
Worddoc: = nil;
End;
If assigned (wordapp) Then // ==== close word ====
Begin
Wordapp. Quit;
Wordapp. Disconnect;
Wordapp. Destroy;
Wordapp: = nil;
End;
End;
End;