Delphi cell merging of Word via OLE

Source: Internet
Author: User

Uses Comobj, word2000
Procedure Tform1.button2click (Sender:tobject);
Var
WordApp, Worddoc,table:olevariant;
filename:string;
Begin
WordApp: = Createoleobject (' Word.Application ');
WordDoc: = WORDAPP.DOCUMENTS.ADD;

Try
WordDoc.PageSetup.LeftMargin: = 0.39*72; 1 inch = 72 lb
WordDoc.PageSetup.RightMargin: = 0.39*72; 1 inch = 72 lb
WordDoc.PageSetup.TopMargin: = 1*72; 1 inch = 72 lb
WordDoc.PageSetup.BottomMargin: = 1*72; 1 inch = 72 lb
WordDoc.PageSetup.PaperSize: = wdPaperA4; A4 paper

WordApp.Selection.Font.Name: = ' blackbody ';
WordApp.Selection.Font.Size: = 22;//Second Font unit: lbs
WordApp.Selection.Font.Bold: = true;//font Bold
WordApp.Selection.Font.Color: = wdcolorblue;//Font Color
WordApp.Selection.ParagraphFormat.Alignment: = wdAlignParagraphCenter; Center text in paragraph
WordApp.Selection.ParagraphFormat.LineSpacingRule: = wdlinespacesingle;//single Spacing
WordApp.Selection.TypeText (' Students ' overall evaluation of teachers ' teaching work ');
wordapp.selection.typeparagraph;//Enter
wordapp.selection.typeparagraph;//Enter


Table: = WordApp.ActiveDocument.Tables.Add (WordApp.ActiveDocument.Paragraphs.item (3). range,2,5); Add a table to the third paragraph (2 rows and 5 columns)

WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Size: = 9;
WordApp.Selection.Font.Bold: = False;
WordApp.Selection.Font.Color: = Wdcolorblack;
Table.cell (a). VerticalAlignment: = Wdcellalignverticalcenter;
WordApp.Selection.TypeText (' teacher name ');

Table. Cell (1, 1). Merge (table. Cell (2, 1));

Table. Cell (1, 2). Merge (table. Cell (1, 5));

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblue;
WordApp.Selection.Font.Bold: = True;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' Comprehensive evaluation of teachers ' teaching work ');
WordApp.Selection.TypeParagraph;
WordApp.Selection.MoveRight (wdcell,1);

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = True;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' A ');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size: = 9;
WordApp.Selection.Font.Bold: = False;
WordApp.Selection.TypeText (' very satisfied ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = True;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' B ');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size: = 9;
WordApp.Selection.Font.Bold: = False;
WordApp.Selection.TypeText (' satisfaction ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = True;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' C ');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size: = 9;
WordApp.Selection.Font.Bold: = False;
WordApp.Selection.TypeText (' basic satisfaction ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = True;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' D ');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size: = 9;
WordApp.Selection.Font.Bold: = False;
WordApp.Selection.TypeText (' dissatisfied ');

WordApp.Selection.MoveRight (wdcell,1);//Add a new line
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = false;
WordApp.Selection.Font.Size: = 10.5;
WordApp.Selection.TypeText (' teacher a ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = true;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' 94 ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 6 ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 0 ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 0 ');


WordApp.Selection.MoveRight (wdcell,1);//Add a new line
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = false;
WordApp.Selection.Font.Size: = 10.5;
WordApp.Selection.TypeText (' teacher B ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.Font.Name: = ' song body ';
WordApp.Selection.Font.Color: = Wdcolorblack;
WordApp.Selection.Font.Bold: = true;
WordApp.Selection.Font.Size: = 12;
WordApp.Selection.TypeText (' 92 ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 8 ');

WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 0 ');
WordApp.Selection.MoveRight (wdcell,1);
WordApp.Selection.TypeText (' 0 ');


Table. Rows.alignment: = wdalignrowcenter;//table Centered
Table. Borders.item (Wdborderleft). Linestyle:=wdlinestylesingle;
Table. Borders.item (wdborderright). Linestyle:=wdlinestylesingle;
Table. Borders.item (Wdbordertop). Linestyle:=wdlinestylesingle;
Table. Borders.item (Wdborderbottom). Linestyle:=wdlinestylesingle;
Table. Borders.item (wdborderhorizontal). Linestyle:=wdlinestylesingle;
Table. Borders.item (wdbordervertical). Linestyle:=wdlinestylesingle;

FileName: = Extractfilepath (paramstr (0)) + ' general rating. Doc ';
Worddoc.saveas (FileName);
Finally
Worddoc.saved: = True;
Worddoc.close;
Wordapp.quit;
End
ShowMessage (' OK ');

End

Delphi cell merging of Word via OLE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.