Delphi word 颜色

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;
 
上一篇:HDU 5044 TREE


下一篇:datareader几种用法总结