//==================Word_VBA code====================//
sub inWord()
Dim myTable As Table
Dim myBox, myPict, myShape As Shape
'Draw the first rectangle
Set myBox = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200)
'Draw a vertical line
Set myLine = ActiveDocument.Shapes.AddLine(255, 70, 255, 270)
'Draw the first picture
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)
'Draw the second picture
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)
'Name
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "Name: Shinnosuke"
'age
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "Age: 12"
'personal information
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "Personal Information"
'Add a table to the text box
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 = "Weight"
myTable.Cell(1, 2).Range.Text = "40kg"
myTable.Cell(2, 1).Range.Text = "Height"
myTable.Cell(2, 2).Range.Text = "120cm"
myTable.Cell(3, 1).Range.Text = "Sit high"
myTable.Cell(3, 2).Range.Text = "65cm"
end sub
//==================Delphi code====================//
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('The storage location of the statistical file has not been selected, and the statistical data cannot be saved! ','Prompt box',mb_ok);
exit;
end;
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
try
//Draw the first rectangle
worddoc.SHAPES.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200);
//Draw a vertical line
worddoc.Shapes.AddLine(255, 70, 255,270);
//Draw the first picture
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=180, Top:=80, Width:=65, Height:=80);
//Draw the second picture
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo/108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=262, Top:=80, Width:=65, Height:=80);
//Draw a name box
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18);
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := 'Name: Shinnosuke';
//age box
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := 'Age: 12';
//Personal information box
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := 'Personal information';
//Add table to text box
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 := 'Weight';
WordTable.Cell(1, 2).Range.Text := '40kg';
WordTable.Cell(2, 1).Range.Text := 'Height';
WordTable.Cell(2, 2).Range.Text := '120cm';
WordTable.Cell(3, 1).Range.Text := 'Sitting high';
WordTable.Cell(3, 2).Range.Text := '65cm';
WordDoc.saveas(filename);
application.MessageBox('Output successful! ','Prompt box',mb_ok);
finally
WordDoc.Saved:=true;
WordDoc.Close;
WordApp.Quit;
end;
end;