码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi word 颜色

时间:2016-03-07 11:59:37      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

unit Unit1;

 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(S<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nhD3PHndrHbkrj03nvf30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnWcvPWc3PWTYPW03rHDLP10zr0" target="_blank" class="baidu-highlight">end</a>er: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  <a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nhD3PHndrHbkrj03nvf30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnWcvPWc3PWTYPW03rHDLP10zr0" target="_blank" class="baidu-highlight">end</a>;
 
var
  Form1: TForm1;
 
implementation
uses
  ComObj,wordXP;
 
{$R *.<a href="https://www.baidu.com/s?wd=dfm&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nhD3PHndrHbkrj03nvf30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnWcvPWc3PWTYPW03rHDLP10zr0" target="_blank" class="baidu-highlight">dfm</a>}
 
procedure TForm1.btn1Click(S<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nhD3PHndrHbkrj03nvf30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnWcvPWc3PWTYPW03rHDLP10zr0" target="_blank" class="baidu-highlight">end</a>er: TObject);
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;
  numb : Integer;
begin
  try
      //启动word应用程序
    FWord:=GetActiveOleObject(‘Word.Application‘);
  except
    FWord := CreateOleObject(‘Word.Application‘);
  end;
  FWord.Visible := true;
 
    try
    //创建一个word文档
    FDOC :=FWord.Documents.Add;
    vActWin   :=   FWord.ActiveWindow;
    FWord.Selection.Font.Name :=‘<a href="https://www.baidu.com/s?wd=%E5%AE%8B%E4%BD%93&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nhD3PHndrHbkrj03nvf30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnWcvPWc3PWTYPW03rHDLP10zr0" target="_blank" class="baidu-highlight">宋体</a>‘; //字体名称
    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);
    //设置第一个单元的背景颜色
    Tables.Cell(1,1).Shading.BackgroundPatternColor := -738131969  ;
 
 
  Except
    on e: Exception do
    begin
      FWord.Quit;
      FWord := Unassigned;
      exit;
    end;
  end;
  {
  //关闭word
  FWord.Quit;
  FWord := Unassigned;
 
  }
end;
 

Delphi word 颜色

标签:

原文地址:http://www.cnblogs.com/zhangzhifeng/p/5249813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!