線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3266
推到 Plurk!
推到 Facebook!

如何在word檔插入我要的圖片

尚未結案
pejhchen
一般會員


發表:1
回覆:1
積分:0
註冊:2004-05-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-04 10:47:16 IP:202.39.xxx.xxx 未訂閱
請教各位大大: 我的問題是如何在開啟已存在的word檔,並在此word檔插入我要的圖片,插入圖片的位置該如何調整???????
pejhchen
一般會員


發表:1
回覆:1
積分:0
註冊:2004-05-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-04 13:28:55 IP:202.39.xxx.xxx 未訂閱
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ToolWin, Word2000, OleServer, StdCtrls, Spin, ExtCtrls, Office2000, WordXP; type TForm1 = class(TForm) WordApplication1: TWordApplication; WordDocument1: TWordDocument; ToolBar1: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; OpenDialog1: TOpenDialog; ToolButton3: TToolButton; FontDialog1: TFontDialog; WordFont1: TWordFont; ToolButton4: TToolButton; ToolButton5: TToolButton; Panel1: TPanel; GroupBox4: TGroupBox; Label6: TLabel; Label7: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; SpinEdit3: TSpinEdit; SpinEdit4: TSpinEdit; SpinEdit5: TSpinEdit; SpinEdit6: TSpinEdit; Edit5: TEdit; Button8: TButton; Button9: TButton; GroupBox2: TGroupBox; Label1: TLabel; Edit1: TEdit; Button3: TButton; GroupBox6: TGroupBox; Label16: TLabel; Edit6: TEdit; Button13: TButton; Label17: TLabel; Edit7: TEdit; SaveDialog1: TSaveDialog; Image1: TImage; //function showfont:string; procedure whenopen(open_type:boolean); procedure FormCreate(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure ToolButton3Click(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Button3Click(Sender: TObject); procedure WordDocument1Close(Sender: TObject); procedure ToolButton5Click(Sender: TObject); procedure WordApplication1Quit(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button13Click(Sender: TObject); private { Private declarations } public { Public declarations } appcon:boolean; end; var Form1: TForm1; WordDocument1, WordApplication1: OleVariant; implementation uses comobj; {$R *.dfm} procedure TForm1.whenopen(open_type:boolean); begin if open_type then begin WordFont1.ConnectTo(WordApplication1.Selection.Font); end; ToolButton2.Enabled:=not open_type; ToolButton3.Enabled:=not open_type; ToolButton5.Enabled:=open_type; GroupBox2.Enabled:=open_type; GroupBox4.Enabled:=open_type; GroupBox6.Enabled:=open_type; end; procedure TForm1.FormCreate(Sender: TObject); begin try Wordapplication1.Connect; appcon:=true; ToolButton1.Down:=Wordapplication1.Visible; if ToolButton1.Down then ToolButton1.Caption:='顯示' else ToolButton1.Caption:='隱藏'; except MessageDlg('無法連上Word', mtError, [mbOk], 0); Abort; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var _savechange:OleVariant; begin _savechange:=wdDoNotSaveChanges; try if not (ToolButton2.Enabled) then WordDocument1.Close(_savechange); finally if appcon then begin if WordApplication1.Documents.Count=0 then WordApplication1.Quit; WordApplication1.Disconnect; end; end; end; procedure TForm1.ToolButton1Click(Sender: TObject); begin if ToolButton1.Down then ToolButton1.Caption:='顯示' else ToolButton1.Caption:='隱藏'; Wordapplication1.Visible := ToolButton1.Down; end; procedure TForm1.ToolButton2Click(Sender: TObject); var Template:OleVariant; begin if OpenDialog1.Execute then begin Template:=OpenDialog1.FileName; WordApplication1.Documents.Open(template,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam); whenopen(true); end; end; procedure TForm1.ToolButton3Click(Sender: TObject); var Template,NewTemplate,ItemIndex,_WordDocumentType,_Visible:OleVariant; begin NewTemplate:=false; //範本為True 文件為False Template := EmptyParam; _WordDocumentType:=wdTypeDocument; _Visible:=true; //沒有用處 可以直接填入emptyparam WordApplication1.Documents.Add(Template, NewTemplate,_WordDocumentType,_Visible); ItemIndex:=1; WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex)); whenopen(true); end; procedure TForm1.Button13Click(Sender: TObject); var WordApplication1, myRange: variant; begin WordApplication1 := CreateOleObject('Word.Application'); WordApplication1.Visible := True; //WordDocu := WordApp.Documents.Open(edit2.text); myRange := WordApplication1.Content; myRange.Find.Execute(FindText := Edit6.text ,ReplaceWith := Edit7.text ); // WordDocument1.FileSaveAs('c:\test.doc'); end; procedure TForm1.Edit1Change(Sender: TObject); begin Button3.Enabled:=not (edit1.text=''); end; procedure TForm1.Button3Click(Sender: TObject); var Linecount:OleVariant; _Unit,_Extend:OleVariant; begin WordApplication1.Selection.Range.InsertAfter(edit1.text #13); // WordDocument1.Range.InsertAfter(edit1.text #13); // Linecount:=length(edit1.text #13); 計算字數 Linecount:=1; _Unit:=wdLine; _Extend:=wdMove; //wdExtend // Wordapplication1.Selection.MoveEnd(Template,Linecount); //移到行尾 // Wordapplication1.Selection.Move(Template,Linecount); Wordapplication1.Selection.MoveDown(_Unit,LineCount,_Extend); end; procedure TForm1.WordDocument1Close(Sender: TObject); begin whenopen(false); end; procedure TForm1.ToolButton5Click(Sender: TObject); var _FileName:OleVariant; begin if SaveDialog1.Execute then begin _FileName:=SaveDialog1.FileName; WordDocument1.SaveAs(_FileName); end; end; procedure TForm1.WordApplication1Quit(Sender: TObject); begin appcon:=false; end; procedure TForm1.Button8Click(Sender: TObject); var s:string; begin s:=OpenDialog1.Filter; OpenDialog1.Filter:='ALL|*.*'; if OpenDialog1.Execute then begin edit5.text:=Opendialog1.FileName; Image1.Picture.LoadFromFile(edit5.Text); SpinEdit5.Value := Image1.Picture.Width; SpinEdit6.Value := Image1.Picture.Height; end; OpenDialog1.Filter:=s; end; procedure TForm1.Button9Click(Sender: TObject); var _Left,_Top,_Width,_Height,_LinkToFile,_SaveWithDocument,_Anchor:olevariant; begin if Fileexists(edit5.text) then begin _LinkToFile:=false; _SaveWithDocument:=true; _Anchor:=EmptyParam; if SpinEdit3.Value=0 then _Left :=EmptyParam else _Left :=SpinEdit3.Value; if SpinEdit4.Value=0 then _Top :=EmptyParam else _Top :=SpinEdit4.Value; if SpinEdit5.Value=0 then _Width :=EmptyParam else _Width :=SpinEdit5.Value; if SpinEdit6.Value=0 then _Height:=EmptyParam else _Height:=SpinEdit6.Value; worddocument1.Shapes.AddPicture(edit5.text, _LinkToFile,_SaveWithDocument,_Left,_Top,_Width,_Height,_Anchor) end; end; end. 這是delphiwww的寫法,但是在我插入圖片時他會再重新開啟一個新的word檔,而不是將圖片插入到已開啟的word檔內,請問該如何修改.......
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-11-25 18:18:45 IP:61.222.xxx.xxx 未訂閱

...
_Height:=SpinEdit6.Value;
worddocument1.Shapes.AddPicture(edit5.text,
_LinkToFile,_SaveWithDocument,_Left,_Top,_Width,_Height,_Anchor)    end;
end;
end.

藍色部份換成下面這行可以加圖在目前的worddocument1 但要加入的位置請再找找方法,找到的話也請貼上方法來貢獻一下
worddocument1.InlineShapes.AddPicture (edit5.text,EmptyParam,EmptyParam,EmptyParam);    
系統時間:2024-05-17 12:41:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!