Delphi and Word (2) get data in the Word table

zhaozj2021-02-17  51

// get data procedure getWordCellStr Word table; var WordApp: TWordApplication; ??? WordDoc: TWordDocument; ??? DocInx, oFileName, CfCversions, oReadOnly, AddToRctFiles, PswDocument, ??? PswTemplate, oRevert, WPswDocument, WPswTemplate, oFormat : Olevariant; ??? I, irow, icol: integer; ??? mycell: core; ??? mycent: 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 ??? docinx: = 1; ??? ofilename: = 'd: /test.doc'; ??? oreadonly: = true; ??? cfcversions : = EmptyParam; ??? AddToRctFiles: = EmptyParam; ??? PswDocument: = EmptyParam; ??? PswTemplate: = EmptyParam; ??? oRevert: = EmptyParam; ??? WPswDocument: = EmptyParam; ??? WPswTemplate: = EmptyParam; ??? o format: = EmptyParam; ???? ??? // ===== Open file ===== ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????? ??? Wordapp.Documents.open (OfileName, Cfcvers, Oradonly, AddtorctFiles, ?????? pswdocument, pswinterplate, orevert, wpswdocument, wpswtemplate, OFORMAT); ??? // ==== = Related file ===== ??? WordDoc.connectto (Wordapp.Documents.Item (Docinx));

??? // method (1) ==> rule table ??? for i: = 1 to worddoc.tables.count do ????? // No. i table ??? begin ????? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? for IROW: = 1 To WordDoc .Tables.Item (i) .rows.count do ????? ????? begin ??????????????????????????????????????????????? ?????????????????? 第 i 列 列 ??????? 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 the horizontal merge? ?? for i: = 1 to WordDoc.tables.count do ????????????? // orthive 第? ??? begin ????? for irow: = 1 to WordDoc. Tables.Item (i) .rows.count do ????? begin ??????? myrow: = worddoc.tables.Item (i) .Rows.Item (iRow); // 第 第 行 ?? ????? for iCol: = 1 to myrow.cells.count do ???????? // ivol column ??????? begin ????????? mycell: = Myrow.cells.Item (iCol); ????????? Memo1.Lines.Add (mycell.range.text); ??????? end; ????? end;??? End; ??? // method (3) ==> irregular: time when the horizontal, longitudinal merge; any table ??? for i: = 1 to worddoc.tables.count do ?????????? ? // 第 表 表 ??? becom GIN ???????????????????????????????????? 第 第 第 el ??????? 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;

转载请注明原文地址:https://www.9cbs.com/read-28950.html

New Post(0)