delphi control word title character and location

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: the Variant; 
  FDOC: the Variant; 
  strSQL: String ; 
  
  iLen: Integer; // for each row the number of bytes 
  S: String ; 
  iDateLen: Integer; 
  iTitleLen: Integer; 
  iSpace: Integer; 
  I: Integer; 
the begin 
  // First create objects, If the exception is to make prompt 

  // FWORD: = CreateOleObject ( 'of the Word.Application'); // //Word.Application.11 2003 when 
  FWORD: = CreateOleObject ( ' Word.Document.12 ' ); // Word. when Application.11 // 2003 
  // execution WOrd program is visible, when the value is false, the program runs in the background. 
  FWord.Application.Visible: = false; 


//Now open Word, create a new page, and then enter the desired contents 
  
  FDOC: = FWord.Application.Documents.Add;
   { for new page Word } 
  FWord.Application.Selection.Font.Name: = ' Arial ' ;
 //   FWord.Application.Selection.Font.Size: = 10; 
//   FWord.Application.Selection.Font.Bold: = 0; 
  { worddoc.PageSetup.LinesPage: = the number of lines per page; 
  worddoc.PageSetup.CharsLine : = words per line; } 


  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 (' new summer tourism diet '); 
//   FWord.Application.Selection.Typeparagraph ; newline // 
//   FWord.Application.Selection.Typeparagraph; newline // 
// FWord.Application.Selection.paragraphs.Alignment: = wdAlignParagraphLeft; 
//   FWord.Application.Selection.Font.Size: = 10; 
//   fword .Application.Selection.Font.Bold: = 0; 
//   FWord.Application.Selection.TypeText ( 'I am now part of the community groups'); 
//   FWord.Application.Selection.TypeText ( 'new summer Tourism lose weight') ; 
// 
//  FWord.Application.Selection.Typeparagraph; // Wrap 
//   FWord.Application.Selection.Typeparagraph; // Wrap 

  // save the document 
  // FWord.Application.Caption: = 'tour plan is saved:' + ExtractFilePath (application.ExeName ) + 'Reports \ xx.doc'; 
  FDOC.SaveAS (ExtractFilePath (Application.ExeName) + ' xx.doc ' );   // E: \ myDelphi7 \ Delphi control word time and head position 

  FWord.Application.Quit; 
  fword : = the Unassigned; 

End ; 

End .

Guess you like

Origin www.cnblogs.com/tobetterlife/p/12169507.html