• delphi控制word 标题 字符和位置


    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls ,OleCtnrs,comobj,Word2000, OleServer;//
    
    type
      TForm1 = class(TForm)
        edtTitle: TEdit;
        btn1: TButton;
        edtDate: TEdit;
        edtlength: TEdit;
        lbl1: TLabel;
        lbl2: TLabel;
        lbl3: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      s:string;
    begin
      s:=DateTimeToStr(Now);
      edtDate.Text:= Copy(s,1,Length(s)-3);
    
      edtTitle.Text:='一二三四五六七八九十';
    
      edtlength.Text:= '40';
    end;
    
    procedure TForm1.btn1Click(Sender: TObject);
    var 
      FWord :Variant;
      FDoc :Variant;
      strSQL :string;
      
      iLen:integer;//每行字节数
      s:string;
      iDateLen:Integer;
      iTitleLen:integer;
      ispace:integer;
      i:Integer;
    begin
      //首先创造对象,如果出现异常就做出提示
    
      //FWord := CreateOleObject('Word.Application'); //Word.Application.11 //2003时
      FWord := CreateOleObject('Word.Document.12'); //Word.Application.11 //2003时
      //WOrd程序的执行是否可见,值为false时,程序在后台运行。
      FWord.Application.Visible := false;
    
    
    //现在打开的Word中,创建一个新的页面,然后在其中键入需要的内容
      
      FDOC :=FWord.Application.Documents.Add;
      {对于Word的新页面}
      FWord.Application.Selection.Font.Name :='宋体';
    //  FWord.Application.Selection.Font.Size :=10;
    //  FWord.Application.Selection.Font.Bold :=0;
      {worddoc.PageSetup.LinesPage := 每页行数;
      worddoc.PageSetup.CharsLine := 每行字数;}
    
    
      FDOC.PageSetup.CharsLine:= edtlength.Text;
    //  FWord.Application.Selection.paragraphs.Alignment := wdAlignParagraphLeft;
    //  FWord.Application.Selection.TypeText(edtdate.text);
      FWord.Application.Selection.paragraphs.Alignment := wdAlignParagraphLeft;
    
      ilen:= StrToInt(edtlength.Text);  //40个汉字
      ilen:= 2*ilen;
     
      iDateLen:= Length(edtDate.Text); //16
      iTitleLen:= Length(edtTitle.Text); //20
    
      ispace:=(iLen div 2)-(iTitleLen div 2)- (iDateLen);
    
      s:= edtDate.Text;
      for i:=0 to ispace-1 do
      begin
        s:=s+' ';
      end;
      s:= s+edttitle.Text;
    
    
      FWord.Application.Selection.TypeText(s);
    
    
    
     // FWord.Application.Selection.TypeText(' 新夏旅游减肥 ');
    //  FWord.Application.Selection.Typeparagraph;//换行
    //  FWord.Application.Selection.Typeparagraph;//换行
    // FWord.Application.Selection.paragraphs.Alignment := wdAlignParagraphLeft;
    //  FWord.Application.Selection.Font.Size :=10;
    //  FWord.Application.Selection.Font.Bold :=0;
    //  FWord.Application.Selection.TypeText(' 现将我社组团部的');
    //  FWord.Application.Selection.TypeText(' 新夏旅游减肥 ');
    //
    //  FWord.Application.Selection.Typeparagraph;//换行
    //  FWord.Application.Selection.Typeparagraph;//换行
    
      //保存文档
      //FWord.Application.Caption := '组团计划保存在: '+ExtractFilePath(application.ExeName)+'Reportsxx.doc';
      FDOC.SaveAS(ExtractFilePath(Application.ExeName)+'xx.doc');  //E:myDelphi7delphi控制word中时间和标题位置
    
      FWord.Application.Quit;
      FWord := Unassigned; 
    
    end;
    
    end.
    书搞进脑袋 创新 创造; 积极
  • 相关阅读:
    HTB-靶机-Charon
    第一篇Active Directory疑难解答概述(1)
    Outlook Web App 客户端超时设置
    【Troubleshooting Case】Exchange Server 组件状态应用排错?
    【Troubleshooting Case】Unable to delete Exchange database?
    Exchange Server 2007的即将生命周期,您的计划是?
    "the hypervisor is not running" 故障
    Exchange 2016 体系结构
    USB PE
    10 months then free? 10个月,然后自由
  • 原文地址:https://www.cnblogs.com/tobetterlife/p/12169507.html
Copyright © 2020-2023  润新知