很简单,通过delphi让word画一条虚线,200分哦。(200分)

  • 主题发起人 主题发起人 zw84611
  • 开始时间 开始时间
Z

zw84611

Unregistered / Unconfirmed
GUEST, unregistred user!
通过delphi让word画一条虚线:

TempWord: OleVariant;

TempWord.ActiveDocument.saveAs('c:/temp.doc');
TempLine := TempWord.ActiveDocument.Shapes.AddLine(x1, y1, x2, y2);
TempWord.ActiveDocument.Selection.ShapeRange.Line.DashStyle := msoLineRoundDot;

无法通过,哪位能帮忙解决。
 
http://www.csdn.net/develop/article/19/19061.shtm

procedure inDelphi;
var
WordApp,WordDoc,WordTable,wordShape:OleVariant; // se:Selection;
filename:string;
begin
SaveDialog1.InitialDir:=ExtractFilePath(Application.ExeName)+'out_file';
SaveDialog1.Execute;
self.Refresh;
filename:=savedialog1.FileName;
if length(filename)=0 then
begin
application.MessageBox(' 没有选择统计文件的存储位置,不能保存统计的数据! ','提示框',mb_ok);
exit;
end;
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
try

//画第一个矩形框
worddoc.SHAPES.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200);
//画一条竖线
worddoc.Shapes.AddLine(255, 70, 255,270);
//画第一幅图
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=180, Top:=80, Width:=65, Height:=80);
//画第二幅图
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=262, Top:=80, Width:=65, Height:=80);

//画 姓名 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18);
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '姓名:新之助';
//年龄 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '年龄:12';
//个人信息 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '个人信息';
//文本框中添加表格
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=288, Top:=198, Width:=189, Height:=63);//.Select;
wordShape.Line.Visible := false;
WordTable := worddoc.Tables.Add(Range:=wordShape.TextFrame.TextRange, NumRows:=3, NumColumns:=2,
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed);
WordTable.Cell(1, 1).Range.Text := '体重';
WordTable.Cell(1, 2).Range.Text := '40kg';
WordTable.Cell(2, 1).Range.Text := '身高';
WordTable.Cell(2, 2).Range.Text := '120cm';
WordTable.Cell(3, 1).Range.Text := '坐高';
WordTable.Cell(3, 2).Range.Text := '65cm';

WordDoc.saveas(filename);
application.MessageBox(' 输出成功! ','提示框',mb_ok);

finally
WordDoc.Saved:=true;
WordDoc.Close;
WordApp.Quit;
end;

end;
 
to Aiirii:
多谢,但是请注意我要画的是虚线。实线我是会画的。

注意是虚线!
 
uses ComObj;
procedure AddDashedToDoc(const DocName: string; const x1, y1, x2 ,y2: Integer);
const
wdAlertsNone = $00000000;
msoLineSolid = $00000001;//实线
msoLineSquareDot = $00000002;//方点线
msoLineRoundDot = $00000003;//圆点线
msoLineDash = $00000004;//虚线
//类推
var
DocApp, DocLine: OleVariant;
begin
try
try
DocApp := CreateOleObject('Word.Application');
DocApp.DisplayAlerts := wdAlertsNone;
DocApp.Documents.Add;
DocLine := DocApp.ActiveDocument.Shapes.AddLine(x1, y1, x2, y2);
DocLine.Line.DashStyle := msoLineDash;
DocApp.ActiveDocument.SaveAs(DocName);
except
end;
finally
if not VarIsEmpty(DocApp) then
DocApp.Quit;
DocApp := Unassigned;
end;
end;
 
多谢vvyang,可以了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部