国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

Delphi與Word例1

2019-11-18 18:35:57
字體:
來源:轉載
供稿:網友
 

//================== Word_VBA 代碼 ====================//
sub inWord()
  Dim myTable As Table
  Dim myBox, myPict, myShape As Shape
 
  '畫第一個矩形框
  Set myBox = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200)
 
  '畫一條豎線
  Set myLine = ActiveDocument.Shapes.AddLine(255, 70, 255, 270)

  '畫第一幅圖
  Set myPict = ActiveDocument.Shapes.AddPicture("D:/test/test/load_jpg1/photo/108259.jpg", _
  LinkToFile:=False, SaveWithDocument:=True, Left:=180, Top:=80, Width:=65, Height:=80)
 
  '畫第二幅圖
  Set myPict = ActiveDocument.Shapes.AddPicture("D:/test/test/load_jpg1/photo/108259.jpg", _
  LinkToFile:=False, SaveWithDocument:=True, Left:=262, Top:=80, Width:=65, Height:=80)
 
  '姓名
  Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18)
  myShape.Line.Visible = msoFalse
  myShape.TextFrame.TextRange.Text = "姓名:新之助"

  '年齡
  Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18)
  myShape.Line.Visible = msoFalse
  myShape.TextFrame.TextRange.Text = "年齡:12"
 
  '個人信息
  Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99)
  myShape.Line.Visible = msoFalse
  myShape.TextFrame.TextRange.Text = "個人信息"

  '文本框中添加表格
  Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=288, Top:=198, Width:=189, Height:=63)
  myShape.Line.Visible = msoFalse

  Set myTable = ActiveDocument.Tables.Add(Range:=myShape.TextFrame.TextRange, NumRows:=3, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
  myTable.Cell(1, 1).Range.Text = "體重"
  myTable.Cell(1, 2).Range.Text = "40kg"
  myTable.Cell(2, 1).Range.Text = "身高"
  myTable.Cell(2, 2).Range.Text = "120cm"
  myTable.Cell(3, 1).Range.Text = "坐高"
  myTable.Cell(3, 2).Range.Text = "65cm"
end sub
//================== Delphi代碼 ====================//
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;


上一篇:Delphi中根據分類數據生成樹形結構的最優方法

下一篇:如何在Delphi應用程序中調用CHM文檔

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 皮山县| 甘南县| 舞钢市| 北安市| 宁强县| 乳山市| 西充县| 乐陵市| 定结县| 安塞县| 江北区| 凤冈县| 新龙县| 武定县| 襄樊市| 涡阳县| 汝州市| 体育| 成武县| 银川市| 徐水县| 商城县| 独山县| 永年县| 玉林市| 和田市| 馆陶县| 读书| 吴桥县| 杭锦后旗| 金湖县| 确山县| 兴业县| 霍邱县| 永川市| 成安县| 古田县| 花垣县| 安宁市| 阳江市| 六盘水市|