uses  ComObj,word2000
 
procedure TForm1.ExportWord();
var
FWord :Variant;
FDoc :Variant;
i,Row:Integer;
nodeString:Tstringlist;
nodeList:TList;
Tables,TablesSub:Variant;
sTableName,sUserName:string;
CfCversions,oReadOnly,AddToRctFiles,
PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat,Where,vActWin:Variant;
UserNameList:TStringList;
begin
  nodeList:=TList.Create;
  UserNameList:=TStringList.Create;
  try
    try
      //启动word应用程序
      FWord:=GetActiveOleObject('Word.Application');
    except
      FWord := CreateOleObject('Word.Application');
    end;
     FWord.Visible := False;
 
    try
    //创建一个word文档
    FDOC :=FWord.Documents.Add;
    vActWin   :=   FWord.ActiveWindow;
    FWord.Selection.Font.Name :='宋体'; //字体名称
    FWord.Selection.Font.Size :=20; //字体大小
    FWord.Selection.Font.Bold :=2; //字体加粗
 
    //设定文字对齐方式
    FWord.Selection.paragraphs.Alignment := wdAlignParagraphCenter;
    //添加文字内容
    FWord.Selection.TypeText('标题一');
    //插入回车符
    FWord.Selection.Typeparagraph;
 
    FWord.Selection.paragraphs.Alignment := wdAlignParagraphLeft;
    FWord.Selection.Font.Size :=12;
    FWord.Selection.Font.Bold :=0;
    FWord.Selection.Typeparagraph;
 
    //添加一个2行3列的表格
    Tables:=FWord.ActiveDocument.Tables.Add(Range:=FWord.Selection.Range,
    NumRows:=2,
    NumColumns:=3,
    DefaultTableBehavior:=1,
    AutoFitBehavior:=0);
    //设置第二行表格的高度
    Tables.Rows.Item(2).SetHeight(250,1);
 
    FWord.Selection.range.rows.headingformat:=wdtoggle;
 
    Tables.rows.allowbreakacrosspages:=wdtoggle;
 
 
    //设置表格第一行的对齐方式
     Tables.Rows.item(1).Alignment   :=   wdAlignRowCenter;
     //向表格添加内容
     Tables.Cell(1,1).Range.Text:='局长';
     Tables.Cell(1,2).Range.Text:='厅长';
     Tables.Cell(1,3).Range.Text:='部长';
     MoveDown(FWord,1);
     //插入一个正方形符号
     FWord.Selection.InsertSymbol(Font:='+中文正文', CharacterNumber:=9633, Unicode:=True);
     FWord.Selection.TypeText('建议以下述方式做'+#13      +'工作的总结'+#13);
    FWord.Selection.Typeparagraph;
 
    TablesSub:=FWord.ActiveDocument.Tables.Add(Range:=FWord.Selection.Range,
    NumRows:=1,
    NumColumns:=1,
    DefaultTableBehavior:=1,
    AutoFitBehavior:=0);
 
    TablesSub.Columns.Item(1).SetWidth(136,1);
    FWord.Selection.TypeText('    ');
    //插入一个园形符号
    FWord.Selection.InsertSymbol(Font:='+中文正文', CharacterNumber:=9675, Unicode:=True);
    FWord.Selection.TypeText('     ');
    FWord.Selection.InsertSymbol(Font:='+中文正文', CharacterNumber:=9675, Unicode:=True);
    FWord.Selection.TypeText('     ');
    FWord.Selection.InsertSymbol(Font:='+中文正文', CharacterNumber:=9675, Unicode:=True);
    FWord.Selection.TypeText(#13);
    FWord.Selection.TypeText(' '+'总结会议'+' '+'公函'+'  '+'电话');
    MoveDown(FWord,1);
    FWord.Selection.TypeText('意见');
    Tables.Cell(2,2).Range.Text:=''+#13+'意见';
    Tables.Cell(2,3).Range.Text:=''+#13+'批示';
    MoveEnd(FWord);
 
    for i:=1 to 30 do
    begin
    FWord.Selection.TypeText('');
    FWord.Selection.Typeparagraph;
    end;
 
    //设置边距  上边距topmargin 下bottommargin 左leftmargin 右 right.....
    FWord.ActiveDocument.pagesetup.topmargin:=20;
    FWord.ActiveDocument.pagesetup.bottommargin:=40;
    FWord.ActiveDocument.pagesetup.leftmargin:=80;
    FWord.ActiveDocument.pagesetup.rightmargin:=100;
 
 
    //操作页尾
     FWord.ActiveWindow.ActivePane.View.SeekView   :=   wdSeekCurrentPageFooter;
     FWord.Application.Selection.ParagraphFormat.Alignment   :=   wdAlignParagraphLeft;
     FWord.Application.Selection.TypeText('人员'+'UserNameList.CommaText');
     FWord.Selection.Typeparagraph;
     FWord.Application.Selection.TypeText('日期'+FormatDateTime('YYYY-MM-DD',now));
     FWord.ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;
 
 
 
    Except
    on e: Exception do
    begin
      FWord.Quit;
      FWord := Unassigned;
      exit;
    end;
    end;
    FWord.Caption :=ExtractFilePath(application.ExeName)+'name.doc';
   //保存为97-2003格式
    FDOC.SaveAS(ExtractFilePath(application.ExeName)+'审计简报.doc',wdFormatDocument);
    //FDOC.SaveAS(ExtractFilePath(application.ExeName)+'name.doc');
    oReadOnly:=False;
    CfCversions := EmptyParam;
    AddToRctFiles:= EmptyParam;
    PswDocument:= EmptyParam;
    PswTemplate:= EmptyParam;
    oRevert:= EmptyParam;
    WPswDocument:= EmptyParam;
    WPswTemplate:= EmptyParam;
    oFormat:= EmptyParam;
    FWord.Documents.open(FWord.Caption,CfCversions,oReadOnly,AddToRctFiles,
    PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
  finally
     Screen.Cursor:=crdefault;
     nodeList.free;
     UserNameList.Free;
  end;
end;
procedure TForm1.MoveEnd(fword:olevariant);
var
unit_: olevariant;
extend: olevariant;
begin
  unit_ := wdstory;
  extend := wdmove;
  fword.selection.endkey(unit_, extend);
end;
 
procedure TForm1.movedown(fword:olevariant;num: integer = 1);
var
unit_: olevariant;
count: olevariant;
extend: olevariant;
begin
  try
  count := num;
  unit_ := wdline;
  fword.selection.movedown(unit_, count, extend);
  except
  end;
end;
procedure TForm1.moveup(fword:olevariant;num: integer = 1);
var
unit_: olevariant;
count: olevariant;
extend: olevariant;
begin
  unit_ := wdline;
  count := 1;
  fword.selection.moveup(unit_, count, extend);
end;

delphi 操作 word的更多相关文章

  1. Delphi 操作word 表格

    var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...

  2. Delphi 操作Word怎么控制光标的位置

    unit ControlWordS; interface uses Classes, Sysutils, Word97; type  TControlWord = class(TComponent)  ...

  3. delphi 换行操作 Word

    delphi 换行操作 我将我的商用<旅行社管理系统>的 发团通知 部分奉献给您,望对您有所帮助. procedure TFrmMain.N327Click(Sender: TObject ...

  4. 用DELPHI操作EXCEL Word

    用DELPHI操作EXCEL 在DELPHI中显示EXCEL文件,可用以下简单代码做到.但要实用,则需进一步完善. var  Form1: TForm1;  EApp:variant;implemen ...

  5. Delphi 统计Word文档中的字数

    急待解决的问题就是如何用delphi实现word中的统计字数 另外想多了解一些关于操作word的相关内容 比如用ole动态创建的和TWordApplication的偏重点在哪里,有什么不同等等…… 用 ...

  6. delphi操作xml学习笔记 之一 入门必读

    Delphi 对XML的支持---TXMLDocument类       Delphi7 支持对XML文档的操作,可以通过TXMLDocument类来实现对XML文档的读写.可以利用TXMLDocum ...

  7. python操作word入门

    1.安装pywin32 http://sourceforge.net/projects/pywin32 在files里去找适合你的python版本.截止此文,最新版本是pywin32-219快捷路径: ...

  8. C#中操作Word(1)—— word对象模型介绍

    一.开发环境布置 C#中添加对Word的支持,只需添加对Microsoft.Office.Interop.Word的命名空间,如下图所示,右键点击“引用”,在弹出的“添加引用”对话框中选中COM标签页 ...

  9. C#操作Word的超详细总结

    本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...

随机推荐

  1. QAQ数论模板笔记√

    #include <cstdio> using namespace std; long long gcd(long long a, long long b) { // (a, b) ret ...

  2. *[hackerrank]Consecutive Subsequences

    https://www.hackerrank.com/contests/w6/challenges/consecutive-subsequences 求数组中被k整除的子段和有几个.这个要利用sum[ ...

  3. *[hackerrank]Die Hard 3

    https://www.hackerrank.com/contests/w7/challenges/die-hard-3 首先,发现c <= max(a, b) 而且 c = aX + bY时有 ...

  4. MVVM 代码记录

      一.XML <Page x:Class="MVVM.MainPage" xmlns="http://schemas.microsoft.com/winfx/20 ...

  5. servlet会话技术:Session

    问题的引出 1.在网上购物时,张三和李四购买的商品不一样,他们的购物车中显示的商品也不一样,这是怎么实现的呢? 2.不同的用户登录网站后,不管该用户浏览该网站的那个页面,都可以显示登录人的名字,同时可 ...

  6. OEM status|start|stop

    OEM一旦建立以后,LINUX的主机名(hosts)就不要去改变. [oracle@redhat4 ~]$ emctl start dbconsoleOC4J Configuration issue. ...

  7. eclipse导入javax.servlet.*的方法

    1.下载web应用服务器tomact,网址http://tomcat.apache.org/download-80.cgi 这个根据自己系统进行选择. 2.将其加压到电脑中 3.在eclipse中添加 ...

  8. CSS+DIV问题!DIV的最小高度问题!

    DIV层的最小高度问题!就是一个DIV有个最小高度,但是如果DIV层中的内容很多,DIV的高度会根据内容而进行拉长!要求IE6.IE7还有firefox都要兼容!我试了很多网上的方法都不好用!请测试后 ...

  9. Web内容管理系统 Magnolia 启程-挖掘优良的架构(3)

    Author and Public instances 第一个关键观念:instance-实例.每一个项目都必须至少有一个Author实例和至少一个Public实例.下面将告诉你为什么: 基本概念:J ...

  10. bzoj1132

    每次都选最左边的点,然后以这个点为原点 统计和这个点构成的三角形面积和 不难想到极角排序然后由叉积很容易求出 shl ; eps=1e-8; var i,j,k,m,n:longint; x,y:.. ...