免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Random thoughts on coding & technology: OLE Automation with Delphi part I

OLE Automation with Delphi part I

Today I'm going to publish about a little application I've been developing recently for one of my clients. This little application pretends to use the Microsoft word OLE Automation to build a document with incrustation of images in it. But Why have I used OLE automation instead of working with the TLB functionality?. That's simple, because working with the OLE can help me with any of the Microsoft documents, and I recommend to work with the TLB when you are sure that you'll be working with a concrete package of Microsoft Office. For example, with the Office 2007, you can use the version 12.0 of the Object Library for your own purpose (but having in mind that you have to follow the license rules) .

The major problem working with OLE is that's difficult to know how exactly do the things that you want. In my case I wanted to insert some stretched pictures inside a word document in a correct position. After seeking out all the information, I've managed to build this little application that will help you to encrust images inside the document.

If we load all the images and try to generate the document, the selected images will be encrusted like the next image:

Notice that It works with word 2003 or 2007 (but I've found some problems with the 2007). Anyway, the little code for encrust an image to a word document would be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
procedure EncrustImage();
var
   WordApplication, WordDocument, CurrentPic: Variant;
   cnt, rgn: variant;
begin
   try
       WordApplication := CreateOleObject('Word.Application');
       WordDocument := WordApplication.Documents.Open(Edit1.Text);
       //get to the last position of the caret
       cnt := WordDocument.Characters.Count;
       cnt := cnt - 1;
       rgn := WordDocument.Range(Start := cnt, end := cnt);
       if path1.text <> '' then
       begin
           rgn.InlineShapes.AddPicture(path1.text);
           CurrentPic := WordApplication.ActiveDocument.InlineShapes.Item(1);
           Currentpic.Height := 170.0; // points
           Currentpic.Width := 225.0;
       end;
       cnt := WordDocument.Characters.Count;
       cnt := cnt - 1;
       rgn := WordDocument.Range(Start := cnt, end := cnt);
       if path2.text <> '' then
       begin
           rgn.InlineShapes.AddPicture(path2.text);
           CurrentPic := WordApplication.ActiveDocument.InlineShapes.Item(2);
           Currentpic.Height := 170.0; // points
           Currentpic.Width := 225.0;
       end;
       cnt := WordDocument.Characters.Count;
       cnt := cnt - 1;
       rgn := WordDocument.Range(Start := cnt, end := cnt);
       rgn.Text := chr(13) + chr(10);
       WordDocument.SaveAs(FileName := Edit2.text + '\out' + ExtractFileName(Edit1.text), AddToRecentFiles := False);
       WordApplication.Quit(False);
   except
       WordApplication.Quit(False);
   end;
end;


You can find this little application here:
Related Articles:
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
怎樣向word文檔中寫入數(shù)據(jù)
部分Office 2007文件格式轉(zhuǎn)換為xps和pdf代碼整理
利用C Builder 中OLE自動化功能實現(xiàn)調(diào)用Word進行報表制作
fastreport的報表轉(zhuǎn)word出現(xiàn)格式怎么解
Delphi控制Word編程手記
create a document write text and save with Word
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服