//==================Word_VBA コード===================//
サブ inWord()
myTable をテーブルとして暗くする
myBox、myPict、myShape をシェイプとして暗くする
'最初の長方形を描画します
Set myBox = ActiveDocument.Shapes.AddTextbox(方向:=1、左:=90、上:=70、幅:=414、高さ:=200)
'縦線を引く
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、左:=180、上:=80、幅:=65、高さ:=80)
'2枚目の絵を描きます
Set myPict = ActiveDocument.Shapes.AddPicture("D:/test/test/load_jpg1/photo/108259.jpg", _
LinkToFile:=False、SaveWithDocument:=True、左:=262、上:=80、幅:=65、高さ:=80)
'名前
Set myShape = ActiveDocument.Shapes.AddTextbox(方向:=1、左:=108、上:=198、幅:=126、高さ:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "名前:しんのすけ"
'年
Set myShape = ActiveDocument.Shapes.AddTextbox(方向:=1、左:=108、上:=225、幅:=126、高さ:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "年齢: 12"
'個人情報
Set myShape = ActiveDocument.Shapes.AddTextbox(方向:=1、左:=351、上:=90、幅:=126、高さ:=99)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "個人情報"
'テキストボックスに表を追加
Set myShape = ActiveDocument.Shapes.AddTextbox(方向:=1、左:=288、上:=198、幅:=189、高さ:=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"
エンドサブ
//==================Delphi コード====================//
Delphi での手順;
変数
WordApp,WordDoc,WordTable,wordShape:OleVariant; // se:Selection;
ファイル名:文字列;
始める
SaveDialog1.InitialDir:=ExtractFilePath(application.ExeName)+'out_file';
SaveDialog1.実行;
self.Refresh;
ファイル名:=savedialog1.ファイル名;
長さ(ファイル名)=0の場合、
始める
application.MessageBox('統計ファイルの保存場所が選択されていないため、統計データを保存できません! ','プロンプトボックス',mb_ok);
出口;
終わり;
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
試す
//最初の長方形を描画します
worddoc.SHAPES.AddTextbox(方向:=1、左:=90、上:=70、幅:=414、高さ:=200);
//垂直線を描きます
worddoc.Shapes.AddLine(255, 70, 255,270);
//最初の絵を描画します
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False、SaveWithDocument:=True、左:=180、上:=80、幅:=65、高さ:=80);
// 2番目の絵を描画します
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False、SaveWithDocument:=True、左:=262、上:=80、幅:=65、高さ:=80);
//名前ボックスを描画します
wordShape:=worddoc.Shapes.AddTextbox(方向:=1、左:=108、上:=198、幅:=126、高さ:=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(ファイル名);
application.MessageBox('出力成功! ','プロンプト ボックス',mb_ok);
ついに
WordDoc.Saved:=true;
WordDoc.Close;
WordApp.終了;
終わり;
終わり;