VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

如何執行word之合併列印功能

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
fjcc9



註冊時間: 2004-06-21
文章: 14


第 1 樓

發表發表於: 星期四 十二月 16, 2004 2:52 pm    文章主題: 如何執行word之合併列印功能 引言回覆

請問:
我想用foxpro 6.0 開啟word文件,並由foxpro程式執行合併列印功能,該如何做?
我知道在vb可用
word.MailMerge.Destination = wdSendToNewDocument
word.MailMerge.Execute
回頂端
檢視會員個人資料 發送私人訊息
syntech



註冊時間: 2003-05-16
文章: 4212
來自: Taipei,Taiwan

第 2 樓

發表發表於: 星期四 十二月 16, 2004 3:15 pm    文章主題: 引言回覆

不知道這樣能不能用,我沒有真的試過:

-----------------
代碼:

    oleWORD=createobject('Word.Application')
    oleWORD.Document.Open("XXX.DOC")
    .
    .
    .
    oleWORD.Document.MailMerge.Destination = wdSendToNewDocument && 可能要定義什麼是 wdSendToNewDocument
    oleWORD.Document.MailMerge.Execute()
    oleWORD.Quit()

_________________
如果公司有下列困擾:
1. 找不到便宜,快速,簡易的 生產排程軟體
2. 不知道如何快速排定 採購計劃
3. 成本抓不準,自己算比軟體算有用
4. 想學習系統規劃,想找系統架構的顧問

請聯絡我們,也許我們幫得上忙
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 AIM Address
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2157


第 3 樓

發表發表於: 星期四 十二月 16, 2004 3:37 pm    文章主題: 引言回覆

wdSendToNewDocument = 0
wdSendToPrinter = 1
wdSendToEmail = 2
wdSendToFax = 3

_________________
利用>>搜尋<<的功能會比問的還要快得到答案.
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
goto-dream



註冊時間: 2004-05-11
文章: 909


第 4 樓

發表發表於: 星期五 三月 25, 2005 3:07 am    文章主題: 引言回覆

轉貼微軟範例
http://support.microsoft.com/kb/181926/EN-US/

代碼:
***/ Begin program code /***
   * Code to create a new data source to a VFP table.
   *
   * Use the Declare DLL function to prototype the
   * SQLConfigDataSource function.
   * Using SQLConfigDataSource prevents having to go into
   * the ODBC Driver Manager and create the DSN.

   ***


IF VAL(SUBSTR(VERSION(4),2,1))>7
lthemes=_screen.Themes
_screen.Themes=.f.
ENDIF

   DECLARE Integer SQLConfigDataSource in odbccp32.dll Integer, ;
      Integer, String, String

   ***
   * Create a string containing the settings appropriate to the driver.
   * The following is an example for the Microsoft VFP ODBC driver
   * accessing the Customer.dbf file.
   ***

   *** Change the path below to point to the Customer table ***
   *** in the \Samples\Data folder.                      ***
   settings="DSN=visual foxpro tables"+chr(0)+;
             "Description=VFP ODBC Driver"+chr(0)+;
             "SourceDB=e:\vfp7\samples\data"+chr(0)+;
             "SourceType=DBF"
   =SQLConfigDataSource(0,1,"Microsoft Visual FoxPro Driver",settings)

   * NOTE: Ensure there are no spaces on either side of the equal sign (=).

   ON ERROR DO errhand WITH ERROR(), MESSAGE(),  MESSAGE(1), PROGRAM( ),
   LINENO( ) && Trap OLE & other errors.

   * Initialize variables passed to Word to create form letter.
   intro1="Congratulations! You are one of our best customers since you have ;
   purchased $"
   intro2=" each month from us. "
   intro3="As a result, your maximum order amount has been increased by ;
   $2500.00. If you have any questions, please feel free to contact us."

   oWord = CREATEOBJECT("Word.Application")
      WITH oWord
         * Assign values to variables
         dsname="e:\VFP7\SAMPLES\DATA\customer.DBF"
         wformat=0
         wconfirmconv=0
         wreadonly=0
         wlinktosource=0
         waddtofilelist=0
         wpassworddoc=""
         wpasswordtemp=""
         wrevert=0
         wprotectdoc=""
         wprotecttemp=""
         wconn="DSN=visual foxpro tables;uid=;pwd=;"+;
            "sourcedb=e:\vfp7\samples\data;sourcetype=dbf"+;
            "exclusive=no;backgroundfetch=yes;collate=machine;"
         wsqlstatement="SELECT contact,company,title,address,city,;
            postalcode,STR(maxordamt,12,2) as maxordamt FROM customer ;
            WHERE (customer.maxordamt>$100000)"

         .Visible=.T.      && Make Word visible.
         .WindowState = 2   && Minimize Word.


         .Documents.Add      && Add new document.
         .Selection.InsertParagraphAfter

         .ActiveDocument.MailMerge.OpenDataSource;
            (dsname,wformat,wconfirmconv,wreadonly,wlinktosource,;
             waddtofilelist,wpassworddoc,wpasswordtemp,wrevert,;
             wprotectdoc,wprotecttemp,wconn,wsqlstatement)
         .ActiveDocument.MailMerge.EditMainDocument
         .Selection.InsertDateTime("dddd, MMMM dd, yyyy", 1)
         .Selection.MoveRight
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"contact")
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"company")
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .ActiveDocument.MailMerge.Fields.Add;
             (oWord.Selection.Range,"title")
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"address")
         .Selection.InsertAfter(", ")
         .Selection.MoveRight
         .ActiveDocument.MailMerge.Fields.Add(oWord.Selection.Range,"city")
         .Selection.InsertAfter("  ")
         .Selection.MoveRight
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"postalcode")
         .Selection.MoveRight
         .Selection.InsertParagraphAfter
         .Selection.InsertParagraphAfter
         .Selection.InsertAfter("Dear ")
         .Selection.MoveRight
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"contact")
         .Selection.MoveRight
         .Selection.InsertAfter(":")
         .Selection.MoveRight
         .Selection.InsertParagraphAfter
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .Selection.InsertAfter(intro1)
         .Selection.MoveRight
         .ActiveDocument.MailMerge.Fields.Add;
            (oWord.Selection.Range,"maxordamt")
         .Selection.MoveRight
         .Selection.InsertAfter(intro2)
         .Selection.MoveRight
         .Selection.InsertAfter(intro3)
         .Selection.MoveRight
         .Selection.InsertParagraphAfter
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .Selection.InsertAfter("Thank you,")
         .Selection.MoveRight
         .Selection.InsertParagraphAfter
         .Selection.InsertParagraphAfter
         .Selection.MoveDown
         .Selection.Fields.Add(oWord.Selection.Range,-1,"author")
         .ActiveDocument.MailMerge.Destination = 0 && new document.
         .ActiveDocument.MailMerge.Execute         && Run the merge.
         nanswer = MESSAGEBOX("Would you like to view the finished ;
         document?",36,"Switch to Word")
         DO CASE
            CASE nanswer = 6
               .ActiveWindow.View.Type = 3    && Page layout view.
               .Visible = .T.
               .Application.Activate   && Bring Word forward.
               .WindowState = 0         && Word in normal state.
               =INKEY(5)         && Wait 5 seconds then bring VFP back.
               .WindowState = 2    && Then minimize Word.
              ENDCASE
         nanswer = MESSAGEBOX("Print the document?",36,;
         "Print the merged document.")
         DO CASE
            CASE nanswer = 6         && Yes
               .ActiveDocument.PrintOut   && Print the merged form letter.
         ENDCASE

         nanswer = MESSAGEBOX("Save the document?",36,;
         "Enter the name to save the merged document.")
         DO CASE
            CASE nanswer = 6         && Yes
               cbaddoc=SPACE(25)
               DO WHILE .T.
                  DEFINE WINDOW getname FROM 1,1 TO 15,60 ;
                     FONT 'COURIER NEW',10 FLOAT GROW ZOOM
                     ACTIVATE WINDOW getname
                     cdoc=SPACE(25)
                     mquit = SPACE(1)
                  IF !EMPTY(cbaddoc)
                     @2,1 SAY "Existing file name: "+cbaddoc COLOR R+/w
                  ENDIF
                  @4,1 SAY "Enter a name for the Word document."
                  @5,1 GET cdoc color b/w VALID emptyChk(cdoc)
                  @7,25 GET mquit FUNCTION '*T Save' SIZE 2,10
                  READ CYCLE
                  CLEAR WINDOW getname
                  cdoc=ALLTRIM(cdoc)
                  cpath= .Options.DefaultFilePath(0)   && Get Word's
                                                 && default document path.
                  IF FILE(cpath+"\"+cdoc+".doc")
                     WAIT WINDOW "Document already exists! Enter another ;
                     file name." TIME 1
                     cbaddoc=cdoc
                     LOOP
                  ELSE
                     .ActiveDocument.SaveAs(cdoc)
                  ENDIF
                  .Documents.Close(0)
                  .Application.Quit
                  EXIT
               ENDDO
            CASE nanswer = 7         && No
               .Documents.Close(0)
               .Application.Quit
            ENDCASE
      ENDWITH

   ON ERROR  && Restore system error handler.
   IF VAL(SUBSTR(VERSION(4),2,1))>7
_screen.Themes=lthemes
   endif

   PROCEDURE emptychk
   PARAMETER pcdoc
   IF !EMPTY(pcdoc)
      RETURN .T.
   ELSE
      WAIT WINDOW "Enter a name for the Word Document"
      RETURN 0
   ENDIF

   PROCEDURE errhand
   PARAMETER merror, mess, mess1, mprog, mlineno
   CLEAR
   IF merror=1426
      mlineno=LTRIM(STR(LINENO()))
      merror=LTRIM(STR(merror))
      =MESSAGEBOX("You have an OLE error. Usually this is caused by
      quitting Word or canceling out of a dialog box in Word. "+CHR(13)+;
      "The error message is "+mess)
   ELSE
      mlineno=LTRIM(STR(LINENO()))
      merror=LTRIM(STR(merror))
      =MESSAGEBOX("An error occured on line "+mlineno+;
      ". The error message is "+mess+" The error number is "+merror)
   ENDIF
   ON ERROR
   RETURN
   ***/ End program code /***

_________________
福隆昌淨水有限公司--淨水器的專家,淨水器,飲水機,濾心!!

想了解更多,您可上幸福雞湯組.找尋!!丁澐瑄.老師.

          愛作夢
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
veteran



註冊時間: 2006-03-30
文章: 5


第 5 樓

發表發表於: 星期四 四月 06, 2006 8:26 am    文章主題: 引言回覆

有人能介绍一下OpenDataSource()函数的参数及参数值的含义吗?

给个链接也行。谢谢!
回頂端
檢視會員個人資料 發送私人訊息
veteran



註冊時間: 2006-03-30
文章: 5


第 6 樓

發表發表於: 星期四 四月 06, 2006 8:42 am    文章主題: 引言回覆

garfield 寫到:
wdSendToNewDocument = 0
wdSendToPrinter = 1
wdSendToEmail = 2
wdSendToFax = 3


到一个已存在并已打开的文档(不是新建的文档newdocument),参数是多少?
回頂端
檢視會員個人資料 發送私人訊息
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作