老兄,看看我的代码,如何合并最后一行的后9个单元格,辛苦了,谢谢[
]
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, comobj, word2000, wordxp;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
NewTable,myRange,Word, Doc:OleVariant; //, Fields
i:integer;
Align,ShowFirst
levariant;
begin
try
Word:=CreateOleObject('Word.Application');
except
application.MessageBox('请安装Microsoft Word 2000 或更高版本!','警告!',mb_ok+mb_iconwarning);
abort;
end;
Word.Visible:=True;
//创建空文档;
Word.Documents.Add();
//将页面改为“横向”;
Word.ActiveDocument.PageSetup.Orientation := wdOrientLandscape;
Word.ActiveDocument.PageSetup.LineNumbering.Active:=False;
Word.ActiveDocument.PageSetup.Orientation := wdOrientLandscape;
Word.ActiveDocument.PageSetup.TopMargin := 2/0.035;
Word.ActiveDocument.PageSetup.BottomMargin := 2/0.035;
Word.ActiveDocument.PageSetup.LeftMargin := 2/0.035;
Word.ActiveDocument.PageSetup.RightMargin := 2/0.035;
Word.ActiveDocument.PageSetup.Gutter := 0;
Word.ActiveDocument.PageSetup.HeaderDistance := 1.2/0.035;
Word.ActiveDocument.PageSetup.FooterDistance := 1.5/0.035;
Word.ActiveDocument.PageSetup.PageWidth := 29.7/0.035;
Word.ActiveDocument.PageSetup.PageHeight := 21/0.035;
Word.ActiveDocument.PageSetup.FirstPageTray := wdPrinterDefaultBin;
Word.ActiveDocument.PageSetup.OtherPagesTray := wdPrinterDefaultBin;
Word.ActiveDocument.PageSetup.SectionStart := wdSectionNewPage;
Word.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter := False;
Word.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter := False;
Word.ActiveDocument.PageSetup.VerticalAlignment := wdAlignVerticalTop;
Word.ActiveDocument.PageSetup.SuppressEndnotes := False;
Word.ActiveDocument.PageSetup.MirrorMargins := False;
Word.ActiveDocument.PageSetup.TwoPagesOnOne := False;
Word.ActiveDocument.PageSetup.GutterPos := wdGutterPosLeft;
Word.ActiveDocument.PageSetup.LayoutMode := wdLayoutModeLineGrid;
Doc := Word.ActiveDocument;
//写入页眉页脚
//写入页眉页脚
If word.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
begin
word.ActiveWindow.Panes(2).Close;
End;
If (word.ActiveWindow.ActivePane.View.Type=wdNormalView)
Or (word.ActiveWindow.ActivePane.View.Type=wdOutlineView) Then
begin
word.ActiveWindow.ActivePane.View.Type:=wdPrintView;
End;
word.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
Word.Selection.Font.NameFarEast:='宋体';
Word.Selection.Font.NameAscii:='Times New Roman';
Word.Selection.Font.NameOther:='Times New Roman';
Word.Selection.Font.Name:='Times New Roman';
Word.Selection.Font.Size:=9;
Word.Selection.Font.Bold:=false;
Word.Selection.Font.Italic:=wdToggle;
Word.Selection.TypeText(Text:='<< 强脑工程业务训练系统 >>');
word.Application.Selection.ParagraphFormat.Alignment := wdAlignParagraphRight;
Align:=wdAlignPageNumberCenter;
ShowFirst:=True;
Word.ActiveDocument.Sections.Item(1).Footers.Item(1).PageNumbers.Add(Align,ShowFirst);
Word.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument;
//写入标题;
Word.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
Word.Selection.Font.NameFarEast:='宋体';
Word.Selection.Font.NameAscii:='Times New Roman';
Word.Selection.Font.NameOther:='Times New Roman';
Word.Selection.Font.Name:='Times New Roman';
Word.Selection.Font.Size:=22;
Word.Selection.Font.Bold := true;
Word.Selection.TypeText(Text:='训练计划');
Word.Selection.TypeParagraph;
Word.Selection.ParagraphFormat.Alignment:= wdAlignParagraphJustify;
Word.Selection.Font.NameFarEast:='宋体';
Word.Selection.Font.NameAscii:='Times New Roman';
Word.Selection.Font.NameOther:='Times New Roman';
Word.Selection.Font.Name:='Times New Roman';
Word.Selection.Font.Size:=9;
Word.Selection.Font.Bold := false;
//Word.Selection.Font.Bold:=wdToggle;
Word.Selection.TypeParagraph;
//画出空表格;
Word.ActiveDocument.Tables.Add(Range:=Word.Selection.Range,
NumRows:=10, //ClientDataSet_tmp.RecordCount+1,
NumColumns:=10,
DefaultTableBehavior:=0,
AutoFitBehavior:=0);
//合并表格
word.Selection.MoveDown(wdLine,1,wdExtend);
word.Selection.Cells.Merge;
word.Selection.MoveRight(1,1,wdMove);
word.Selection.MoveRight(1,5,wdExtend);
word.Selection.Cells.Merge;
word.Selection.MoveRight(2,1,wdMove);
word.Selection.MoveDown(wdLine,1,wdExtend);
word.Selection.Cells.Merge;
word.Selection.MoveRight(3,1,wdMove);
word.Selection.MoveDown(wdLine,1,wdExtend);
word.Selection.Cells.Merge;
word.Selection.MoveRight(3,1,wdMove);
word.Selection.MoveDown(wdLine,1,wdExtend);
word.Selection.Cells.Merge;
word.Selection.MoveRight(3,1,wdMove);
word.Selection.MoveDown(wdLine,1,wdExtend);
word.Selection.Cells.Merge;
end;
end.