全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2565
推到 Plurk!
推到 Facebook!

word 預覽 列印問題

尚未結案
carter6
初階會員


發表:53
回覆:108
積分:42
註冊:2002-12-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-12 16:06:09 IP:218.170.xxx.xxx 未訂閱
大家好: 我用 WordApplication 和 WordDocument 去開 Word, 但是我要讓它直接按 Button 就可以 預覽 或 列印 但是不要開 Word (隱藏) , 也就是不要讓使用者知道我有開過 Word , 就可以直接列印或預覽 謝謝!! Carter
yachanga
資深會員


發表:24
回覆:335
積分:296
註冊:2003-09-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-12 23:44:36 IP:61.230.xxx.xxx 未訂閱
Hi carter6您好: 您的問題是否想要用Delphi程式中的某個按鈕執行列印Word文件?  如果是可參考下面這篇...william 版大的文章 http://delphi.ktop.com.tw/topic.php?topic_id=43184    也可以參考天使的文章, 看看能不能找到您要的?? http://delphi.ktop.com.tw/topic.php?topic_id=22331    
var
    Word: TWordApplication;
    vFile: OleVariant;
begin
    vFile := 'c:\test.doc';
    Word := TWordApplication.Create(self);
    try
        Word.ActivePrinter := 'APF Fax Printer';
        Word.Documents.Open(vFile,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
            EmptyParam);
        Word.ActiveDocument.PrintOut(EmptyParam,EmptyParam,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam);
        while Word.BackgroundPrintingStatus>0 do
            Application.ProcessMessages;
    finally
        Word.Quit;
        Word.Free;
    end;
end;    
發表人 - yachanga 於 2004/05/12 23:47:38
carter6
初階會員


發表:53
回覆:108
積分:42
註冊:2002-12-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-13 11:46:09 IP:218.170.xxx.xxx 未訂閱
你可能誤解我的意思了 這是我寫測試用的 procedure TForm1.Button1Click(Sender: TObject); var templateName,newTemplate,Template,ItemIndex,_Type:OleVariant; s:string; i,j,k:integer; sum:real; begin _Type:=wdSectionBreakNextPage; s:= 'd:\temp\word 套表\' 'temp.doc'; templateName := 'd:\temp\word 套表\temp.doc'; i := 1 ; newTemplate := False; Template:=s; WordApplication1.Documents.AddOld(templateName, newTemplate); ItemIndex:=1; WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex)); WordDocument1.PageSetup.PageWidth := WordDocument1.Application.CentimetersToPoints(strtofloat('25.7')); WordDocument1.PageSetup.PageHeight := WordDocument1.Application.CentimetersToPoints(strtofloat('36.4')); WordDocument1.Range.Select; WordDocument1.Range.Cut; Worddocument1.Range.Characters.Last.select; Worddocument1.Range.Characters.Last.paste; WordDocument1.Tables.Item(i).Cell(1,1).Select; repl('st_name','XXX公司'); repl('us_name','XXX先生'); WordDocument1.Tables.Item(i).Columns.Item(2).Width := WordDocument1.PageSetup.PageWidth - WordDocument1.PageSetup.LeftMargin - WordDocument1.PageSetup.LeftMargin - WordDocument1.Tables.Item(i).Columns.Item(1).Width ; WordDocument1.Tables.Item(i).Cell(1,1).Range.Text:= '11' ; WordDocument1.Tables.Item(i).Cell(1,2).Range.Text:= '12' ; WordDocument1.Tables.Item(i).Cell(1,2).select; insertoneline; WordDocument1.Tables.Item(i).Cell(2,1).Range.Text:= '21' ; WordDocument1.Tables.Item(i).Cell(2,2).Range.Text:= '22' ; WordDocument1.Tables.Item(i).Cell(2,2).select; insertoneline; WordDocument1.Tables.Item(i).Cell(3,1).Range.Text:= '31' ; WordDocument1.Tables.Item(i).Cell(3,2).Range.Text:= '32' ; WordDocument1.Tables.Item(i).Cell(3,2).select; WordDocument1.Range.Characters.Last.Delete(emptyparam,ItemIndex); WordApplication1.Visible:= True ; WordDocument1.PrintPreview; WordDocument1.Disconnect; WordApplication1.Disconnect; end; 當WordApplication1.Visible:= True ; 就會顯示 Word 的 可是我不要讓 Word 顯示出來讓 User 看到 可是我卻要讓他們可以 WordDocument1.PrintPreview; 預覽 列印結果 或是 列印 我應該怎麼做?? 謝謝!!
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-13 19:59:54 IP:218.163.xxx.xxx 未訂閱
1.Delphi填入資料到WORD 2.顯示WORD程式==>WORD編輯視窗 3.WORD預覽==>WORD預覽視窗    基本上會出現兩個WORD視窗:WORD編輯視窗、WORD預覽視窗    若要我選的話,可能給使用者看到 WORD編輯視窗。
carter6
初階會員


發表:53
回覆:108
積分:42
註冊:2002-12-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-05-13 22:26:49 IP:139.175.xxx.xxx 未訂閱
就是因為不要讓使用者看到 WORD編輯視窗 請問有沒有什麼方式可以解決??
saydo
一般會員


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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-05-15 21:58:01 IP:211.20.xxx.xxx 未訂閱
//用Word作Preview... 那使用者都要裝Wordㄟ... 很傷本喔... //可以用QuickRep作Preview... 反正只是要列印嘛!!! //不過還是貼程式試試 用【Word 作 Preview】 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Excel97, Word97, OleServer; type TForm1 = class(TForm) Button1: TButton; Button3: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure Button2Click(Sender: TObject); private WordApplication1: TWordApplication; WordDocument1: TWordDocument; m_Left : integer; m_Top : integer; m_Height : integer; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormShow(Sender: TObject); begin WordApplication1 := NIL; WordDocument1 := NIL; end; procedure TForm1.Button1Click(Sender: TObject); var ItemIndex:OleVariant; i : integer; f_temp : string; begin m_Left := self.Left; m_Top := self.Top; m_Height := self.Height; self.Left := 531; self.Top := 0; self.Height := 57; self.FormStyle := fsStayOnTop; self.VertScrollBar.Visible := False; self.HorzScrollBar.Visible := False; self.BorderIcons := []; if WordApplication1 = NIL then WordApplication1 := TWordApplication.Create(Application); if WordDocument1 = NIL then WordDocument1 := TWordDocument.Create(Application); WordApplication1.Connect; WordApplication1.Documents.Add(EmptyParam, EmptyParam); ItemIndex := WordApplication1.Documents.Count; WordDocument1.connectTo(WordApplication1.Documents.Item(ItemIndex)); WordApplication1.Visible:= True ; WordApplication1.CommandBars.Get_Item('Print Preview').Set_Enabled(true); //開啟【預覽列印】工具列 for i:=1 to WordApplication1.CommandBars.Get_Item('Print Preview').Controls.Count do begin f_temp := WordApplication1.CommandBars.Get_Item('Print Preview').Controls.Item[i].Get_accName(EmptyParam); if f_temp = '關閉' then WordApplication1.CommandBars.Get_Item('Print Preview').Controls[i].Delete(True); //關閉【預覽列印】工具列 【關閉】按鍵 end; WordApplication1.ActiveWindow.View.Set_FullScreen(True); //開啟【全螢幕】 WordApplication1.CommandBars.Get_Item('Full Screen').Set_Enabled(false); //關閉【全螢幕】工具列 WordApplication1.CommandBars.Get_Item('Menu Bar').Set_Enabled(false); //關閉【功能表】工具列 WordDocument1.PrintPreview; WordDocument1.Disconnect; WordApplication1.Disconnect; end; procedure TForm1.Button3Click(Sender: TObject); var i : integer; begin WordApplication1.CommandBars.Get_Item('Print Preview').Set_Enabled(false); //關閉【預覽列印】工具列 for i:=1 to WordApplication1.CommandBars.Get_Item('Print Preview').Controls.Count do begin if WordApplication1.CommandBars.Get_Item('Print Preview').Get_accName(EmptyParam) = '關閉' then WordApplication1.CommandBars.Get_Item('Print Preview').Controls[i].Delete(False); //關閉【預覽列印】工具列 【關閉】按鍵 end; WordApplication1.ActiveWindow.View.Set_FullScreen(False); //關閉【全螢幕】 WordApplication1.CommandBars.Get_Item('Full Screen').Set_Enabled(True); //開啟【全螢幕】工具列 WordApplication1.CommandBars.Get_Item('Menu Bar').Set_Enabled(true); //開啟【功能表】工具列 WordApplication1.Quit; self.Left := m_Left; self.Top := m_Top; self.Height := m_Height; self.FormStyle := fsNormal; self.BorderIcons := [biSystemMenu]; self.VertScrollBar.Visible := true; self.HorzScrollBar.Visible := true; WordDocument1.Free; WordApplication1.Free; WordDocument1 := NIL; WordApplication1 := NIL; end; procedure TForm1.Button2Click(Sender: TObject); var ItemIndex:OleVariant; i,j : integer; begin memo1.Clear; if WordApplication1 = NIL then WordApplication1 := TWordApplication.Create(Application); if WordDocument1 = NIL then WordDocument1 := TWordDocument.Create(Application); WordApplication1.Connect; WordApplication1.Visible := False; WordApplication1.Documents.Add(EmptyParam, EmptyParam); ItemIndex := WordApplication1.Documents.Count; WordDocument1.connectTo(WordApplication1.Documents.Item(ItemIndex)); with WordApplication1.CommandBars do begin for i := 1 to Count do begin memo1.Lines.Add(Item[i].Name '---' Item[i].NameLocal '---' IntToStr(Item[i].accChildCount)); for j:=1 to Item[i].Controls.Count do begin memo1.Lines.Add('--------' Item[i].Controls.Item[j].Get_accName(EmptyParam) ' ' Item[i].Controls.Item[j].Caption ' ' Item[i].Controls.Item[j].DescriptionText); end; end; end; WordDocument1.Disconnect; WordApplication1.Disconnect; WordApplication1.Quit; WordDocument1.Free; WordApplication1.Free; WordDocument1 := NIL; WordApplication1 := NIL; end; end.
系統時間:2024-06-24 21:00:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!