Office Automation Programming (1)

xiaoxiao2021-03-06  126

1: Control Word documentation

{Display Word file}

Var newword: variant;

...

NewWord: = CreateoleObject ('Word.Application');

{

After the CreateoleObject function creates a Word's COM object, Word is completely constructed.

A Word process already exists in memory, created Application objects

}

Newword.visible: = true; // Display Word program

NewWord.Documents.add; // Add a Word document, Application.Documents nested class

NewWord.Documents.Item (1) .range.text: = STR;

Document: = newword.documents.Item (1);

Document.Paragraphs.Add;

MyRange: = Document.range (start: = 0, end: = 0);

2: Add a string to the existing Word table

{Create a new Word document with the specified template file} WordApp.Documents.add (TemplateName, NewTemplate); Wordapp.caption: = listbox1.items.strings [listbox1.itemindex];

Case ListBox1.itemindex of 0: begin {Take the 1st table} {Document in the document} vtable: = Wordapp.activeDocument.table: = wordapp.activedocument.table: = wordapp.activedocument.tables.Item (1); vtable.cell (1, 2 ) .Range.text: = 'Li Xin in Beijing Power Supply Company'; VTable.cell (1, 4) .range.text: = 'Kunming Rui Software';

VTable.cell (2, 2) .range.text: = 'Kunming Baita Road Extension Line 387 Xingyao Building 1102B Li Xin (Received) 650051 (0871) 3126628';

Vtable.cell (3, 2) .range.text: = DATETOSTR (NOW); vTable.cell (3, 4) .range.text: = DateTostr (now);

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

New Post(0)