使用OleContainer连结Word以后,如何用程序自动添加页眉页脚

song317 2003-02-12 06:27:51
有会的不吝赐教了。
...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
song317 2003-02-12
  • 打赏
  • 举报
回复
呵呵,好用。结帖了。
Billy_Chen28 2003-02-12
  • 打赏
  • 举报
回复
使用OleContainer:
OleContainer1.OleObject.Sections.Item(wdHeaderFooterPrimary).
Headers.Item(wdHeaderFooterPrimary).Range.Text:='sdfsdf';
Billy_Chen28 2003-02-12
  • 打赏
  • 举报
回复
begin
try
Template := EmptyParam;
NewTemplate := false;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('你没有安装WORD软件!', mtError, [mbOk], 0);
Abort;
end;
autoformat:=true;
Wordapplication.Visible := True;
WordApplication.Caption := '自动生成WORD文件表格';
Template := EmptyParam;
NewTemplate := False;
if ChkBoxNewDoc.Checked then
begin
WordApplication.Documents.Add(Template, NewTemplate);
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
end;//建立文档
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
pagew:=WordDocument.PageSetup.PageWidth-worddocument.PageSetup.Get_rightMargin-worddocument.PageSetup.Get_leftMargin;
//pagew是页面设置表格的总宽度
with WordDocument do
begin
tables.Add(WordDocument.Words.Last,self.DBGrid.DataSource.DataSet.RecordCount+1,self.DBGrid.DataSource.DataSet.FieldCount);
//插入表格
gridw:=0;
for rowi:=0 to dbgrid.Columns.Count-1 do //建立单元格宽度
begin
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Bold := 1;
tables.Item(1).Cell(1,rowi+1).Range.Set_Text(DBGrid.Columns[rowi].Title.Caption);
gridw:=gridw+dbgrid.Columns[rowi].Width;
end;
for rowi:=0 to dbgrid.Columns.Count-1 do
begin
grideveryw:=((dbgrid.Columns[rowi].Width-2) / gridw)*(pagew);
tables.Item(1).Columns.item(rowi+1).Set_Width(grideveryw);
end;
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Bold := 0;
DBGrid.DataSource.DataSet.first;
for coli:=0 to self.DBGrid.DataSource.DataSet.RecordCount-1 do
begin
for rowi:=0 to dbgrid.Columns.Count-1 do
begin
try
case DBGrid.Columns[rowi].Field.DataType of
ftGraphic://如果是图
begin
DBImgFishImg.CopyToClipboard;
tables.Item(1).Cell(coli+2,rowi+1).Range.Paste;
end;
ftMemo:
begin
tables.Item(1).Cell(coli+2,rowi+1).Range.Set_Text('简要介绍(略)');
end;
else
tables.Item(1).Cell(coli+2,rowi+1).Range.Set_Text(DBGrid.DataSource.DataSet.Fields[rowi].AsString);
end;
except
end;
end;
DBGrid.DataSource.DataSet.Next;
end;
end;
WordDocument.Range.PageSetup.Set_BottomMargin(100);
WordDocument.Range.InsertAfter('表格填写结束!');
worddocument.PageSetup.Set_Gutter(30);
worddocument.PageSetup.Set_GutterOnTop(true);
coli:=1;
with WordDocument do
begin
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes.Item(2).Close; //.Panes[2].Close;

ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;//显示页眉
Application.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter; //中间对齐
//wdAlignParagraphRight:右边对齐;
//wdAlignParagraphJustify:两边对齐;
//wdAlignParagraphLeft:左边对齐;
//wdAlignParagraphCenter:中间对齐;
Application.Selection.TypeText('dcsdcs初次开发的软件,设置页眉!酷吧!!!');
ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageFooter;//显示页脚
Application.Selection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
Application.Selection.TypeText('dcsdcs初次开发的软件,设置页脚!酷吧!!!');
ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;
end;
BtnCloseWord.Enabled := True;
BtnPrint.Enabled := True;
BtnPreview.Enabled := True;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧