When Dephi encounters words

xiaoxiao2021-03-06  41

A set of Servers components in DepHi 5, implements a seamless combination with Office, but there are very few information about this aspect. Recently, the author has contacted a user case, requiring eventually summing the results in the database into one word. Documentation, Word documents have certain requirements for headers, fonts, font numbers, and documents, and also refer to data in a table in the form of a table.

By looking for VBA's instructions, the author finally implemented all functions, and the contents of the relevant content are summarized as follows: 1. Word file named in the current program directory EXEPATH: = Application.exename; for Index: = 1 to length (execex) DO if execth [index] = '/' THEN i: = index; execPath: = COPY (ExEPath, 1, i); doc_file: = exepath mc '. doc'; with title Field "MC" named Word file TRY WordApplication1.connect; Except Messagedlg ('No Word', MTERROR, [MBOK], 0); Abort; End; WordApplication1.caption: = 'XX Program'; WordApplication1.Visible: = true; Worddocument1.activate; 2, set the paper size Wordapplication1.ActiveDocument.PageSetup.PageWidth: = XXX; Wordapplication1.ActiveDocument.PageSetup.PageHeight: = XXX; Wordapplication1.ActiveDocument.PageSetup.LeftMargin: = XX; // left margin Wordapplication1 .ActiveDocument.PageSetup.rightMargin: = XX; // Sets the right margin 3, insert a page number var fpage, pagea: olevariant; fpage: = true; pagea: = wdAlignPageNumberCenter; Wordapplication1.activedocument.sections.item (1) .Footers.item (1) .pagenumbers.add (pagea, fpage); 4, set the page horizontal print S: = WordApplication1.Selection.Start; E: = WordApplication1.Selection.Start; AA: = WdSectionBreakNextPage; Wordapplication1.ActiveDocument.Range (s, e) .InsertBreak (aa); Wordapplication1.Selection.Start: = Wordapplication1.Selection.Start 1; s: = Wordapplication1.Selection.start; e: = Wordapplication1.ActiveDocument. Content.End_; Wordapplication1.ActiveDocument.Range (S, e) .PageSetup.Orientation: = wdOrientLandscape; 5, set font, font size Wordapplication1.Selection.Font.Size: = 18; Wordapplication1.Selection.Font.Name: = 'blackbody '; WordApplication1.Selection.TypeParagraph; WordApplication1.Selection.ParagraphFormat.Alignment: = WDALIGNPARAGRAPHCENTER Download

Wordapplication1.Selection.TypeParagraph; Wordapplication1.Selection.TypeText (dbedit4.text); // Title Wordapplication1.Selection.Font.Size: = 14; Wordapplication1.Selection.Font.Name: = 'Arial'; Wordapplication1.Selection.TypeParagraph; Wordapplication1.Selection.TypeParagraph; Wordapplication1.Selection.ParagraphFormat.Alignment: = wdAlignParagraphJustify; Wordapplication1.Selection.TypeText ( '' trim (dbmemo1.text)); // ... ... body 6, inserting table Wordapplication1.Selection .Font.size: = 10; adoQuery2.active: = false; adoquery2.active: = true; doc: = WordApplication1.actiVedocument; counts: = adoQuery2.recordcount; // record number Decide the table T: = DOC. Tables.add (WordApplication1.Selection.Range, Counts 1, 5); // 5 column T.cell (1, 1) .range.text: = 'unit'; t.cell (1, 1) .width: = 120; T.cell (1, 1) .Range.Paragraphs.Alignment: = wdalignparagraphCenter; T.cell (1, 2) .range.text: = 'Name'; ... // write in Other fields for i: = 2 to counts 1 do begin t.cell (i, 1) .Range.text: = adoquery2.field byname ('dw'). Asstring; t.cell (i, 1) .Width: = 120; T.cell (i, 1) .Range.Paragraphs.Alignment: = WDalignParagraphCenter; T.cell (i, 2) .range.text: = adoquery2.field byname ('xm'). asstring; ... ... AdoQuery2.next; end; use DEPHI to combine Word and database to achieve automatic generation of user documents, greatly facilitating users. Examined from programming enthusiast sites

http://www.programfan.com/showArticle.asp?id=2147

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

New Post(0)