Procedure getwordcellstr;
VaR
Wordapp: twordapplication;
Worddoc: tworddocument;
Dockers, filename, cfcversions, isreadonly, addtorctfiles, pswdocument,
Pswtemplate, revert, wpswdocument, wpswtemplate, formatword: olevariant;
I, irow, icol: integer;
Mycell: cell;
Myrow: row;
Begin
Memo. 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;
Filename: = 'd:/test.doc ′;
Isreadonly: = true;
Cfcversions: = emptyparam;
Addtorctfiles: = emptyparam;
Pswdocument: = emptyparam;
Pswtemplate: = emptyparam;
Revert: = emptyparam;
Wpswdocument: = emptyparam;
Wpswtemplate: = emptyparam;
Formatword: = emptyparam;
// ===== Open the file =====
Wordapp. Documents. Open (filename, cfcversions, isreadonly, addtorctfiles,
Pswdocument, pswtemplate, revert, wpswdocument, wpswtemplate, formatword );
// ===== 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;