uses ComObj;
const
msoTrue = $FFFFFFFF;
msoFalse = $00000000;
wdBorderTop = $FFFFFFFF;
wdBorderLeft = $FFFFFFFE;
wdBorderBottom = $FFFFFFFD;
wdBorderRight = $FFFFFFFC;
wdLineStyleNone = $00000000;
wdLineStyleSingle = $00000001;
wdNewBlankDocument = $00000000;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var FWord :OleVariant; //Word应用程序
FDocument :OleVariant; //文档
FFrame:OleVariant;
begin
FWord:= CreateoleObject('Word.Application');
FDocument:=FWord.Documents.Add(,,wdNewBlankDocument,); //新的文档
//建立文字框
FFrame:=FDocument.Shapes.AddTextbox($00000001,10,10,200,200);
//内容
FFrame.TextFrame.TextRange.Text:='你的文字';
//文字框上下左右边距
FFrame.TextFrame.MarginLeft:=0;
FFrame.TextFrame.MarginRight:=0;
FFrame.TextFrame.MarginTop:=0;
FFrame.TextFrame.MarginBottom:=0;
FFrame.select;
//设置文字字体
FDocument.Application.Selection.font.size:=10;
FDocument.Application.Selection.font.name:='宋体';
FDocument.Application.Selection.font.color:=clred;
//框的填充
FFrame.Fill.Visible:=msofalse;
FFrame.Fill.ForeColor.RGB:=clred; //填充颜色
//框线的宽度,线型,颜色
FFrame.Line.Visible := msotrue;
FFrame.Line.ForeColor.RGB :=clred;
FFrame.Line.Weight :=3;
FFrame.Line.DashStyle :=2;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderLeft).Color:=clred;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderTop).LineStyle:=wdLineStyleSingle;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderTop).Color:=clred;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderright).LineStyle:=wdLineStyleSingle;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderRight).Color:=clred;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
FDocument.Application.Selection.ParagraphFormat.Borders.item(wdBorderBottom).Color:=clred;
FWord.Visible:=true;
end;
刚刚测试通过了的