如何在 Word 97 中,或從針對 Windows 5.0 Visual FoxPro 和更新版本的 Office Word 2003 中建立分類的資料表

重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。

按一下這裡查看此文章的英文版本:180901
本文已封存。本文係以「現狀」提供且不會再更新。
結論
本文將告訴您,如何建立及設定 Microsoft Word 97 或針對 Windows 5.0 Visual FoxPro,並稍後使用 OLE 自動化的 Microsoft Office Word 2003 中表格的格式。 [] 表格包含分組欄位的執行個體中、 狀態、 公司或客戶的銷售識別碼。本範例依國家或地區群組。使用 SQL 查詢為暫時的資料指標收集資料的 Word 文件。
其他相關資訊
這個程式碼正常運作在查詢中的第一個欄位必須在 Word 97 報表中使用的群組欄位。比方說如果它是需要使用報表的資料表中的所有欄位,但就是 [群組] 欄位的欄位是不第一個欄位來源資料表中的,然後發出查詢與此類似:
SELECT state,* FROM Customer GROUP BY state, custid INTO CURSOR category				
這會強制群組欄位在此範例,是第一個欄位在查詢結果中的狀態。

注意: 這個程式碼只適用與 [服務發行-1 代表 Word 97。使用先前版本的 Word 97 引起一個 」 類型不符 」 和其他 OLE 錯誤。

建立一個程式,並輸入下面所列的程式碼。執行程式碼時使用者會看到兩個提示。這些提示詢問使用者如何格式化 Word 文件。第一個提示詢問使用者是否想要有對每個群組它自己的網頁或非。第二個問題詢問使用者是否底線之資料表的資料列之間與否。這些問題是只是用來檢視喜好設定以及顯示如何程式設計人員可能會格式化在 Word 中的表格,與這些和其他喜好設定。

以下是範例程式碼:
    */ Begin program code /*       CLEAR       SET TALK OFF       SET CONSOLE OFF       ctempfield = ""               && Variable to hold group category.       headings_added = .F.       newgrouppage = .F.   * Make sure the FIRST field in the SELECT is the field the report   * is categorized by. The Customer table is located in the   * \VFP\Samples\Data folder. In Visual FoxPro 6.0, the Customer table is   * in the Microsoft Visual Studio\Common\Samples\Data folder.       ** We toggle the value of SET ENGINEBEHAVIOR in VFP 8.0 and    ** 9.0 to allow this SELECT-SQL command to function.     **  For more information on the SET ENGIENBEHAVIOR command,    ** see the VFP Help file.    IF "8.0"$VERSION() OR "9.0"$VERSION()x=SET("enginebehavior")SET ENGINEBEHAVIOR 70   SELECT country, company, contact, title,maxordamt,phone;   FROM HOME()+"Samples\Data\testdata!customer" GROUP BY;      country,cust_id INTO CURSOR category      SET ENGINEBEHAVIOR x      ELSE      SELECT country, company, contact, title,maxordamt,phone;   FROM HOME()+"Samples\Data\testdata!customer" GROUP BY;      country,cust_id INTO CURSOR categoryendif   IF _TALLY > 0      oWord = CREATEOBJECT("Word.Application")      oWord.Documents.Add      owRange = oWord.Activedocument.Range(0,0)      numcols = FCOUNT()-1   && Get number of fields for detail section      oWord.Activedocument.Tables.Add(owRange, 1, numcols)      * First prompt, separate pages for each group.      nanswer = messagebox("Put each group on a new page?",36,;         "Sepatate Pages")      DO CASE         CASE nanswer = 6         && Yes            newgrouppage = .T.         CASE nanswer = 7         && No            headings_added = .F.      ENDCASE      WAIT WINDOW "Please wait while the data is formatted in Word.";         + CHR(13)+"This may take several minutes..." NOWAIT      DO WHILE !EOF()         ctempfield = EVAL(FIELD(1)) && Set 1st field in table as category         WITH oWord            .Selection.Font.Reset            .Selection.TypeText(EVAL(FIELD(1)))            .Selection.SelectRow            .Selection.ParagraphFormat.Alignment = 1            .Selection.Font.Name = "Arial"            .Selection.Font.Size = 16            .Selection.Font.Bold = .T.            .Selection.SelectRow            .Selection.Cells.Merge            .Selection.MoveRight(12)            .Selection.Cells.Split(1,numcols)            IF NOT headings_added && Put at least one heading in document               .Selection.MoveRight(12)               FOR i = 2 TO FCOUNT()                  .Selection.Font.Italic = .T.                  .Selection.ParagraphFormat.Alignment = 1                  .Selection.Font.Name = "Times New Roman"                  .Selection.Font.Size = 8                  .Selection.TypeText((FIELD(i)))                  .Selection.MoveRight(12)                  headings_added = .T.               ENDFOR            ENDIF            FOR i = 2 TO FCOUNT()               curfield = EVAL(FIELD(i))   * Check data type. Does not check Double, Float, Integer, General, Memo.               IF TYPE((FIELD(i)))<>"C"               DO CASE                  CASE TYPE((FIELD(i))) = "D"         && Date field                     curfield = DTOC((FIELD(i)))                  CASE TYPE((FIELD(i))) = "N"         && Numerical                     curfield = STR((FIELD(i)))                  CASE TYPE((FIELD(i))) = "Y"         && Currency                     curfield = STR(EVAL(FIELD(i)),8,2)                  CASE TYPE((FIELD(i))) = "L"         && Logical                     IF curfield                        curfield = "True"                     ELSE                        curfield = "False"                     ENDIF                  CASE TYPE((FIELD(i))) = "T"         && DateTime                     curfield = TTOC(EVAL(FIELD(i)))                  ENDCASE                  .Selection.Font.Reset                  .Selection.TypeText(curfield)               ELSE                  .Selection.Font.Reset                  .Selection.TypeText(curfield)               ENDIF               .Selection.Font.Reset               .Selection.MoveRight(12)            ENDFOR            SKIP         ENDWITH         DO WHILE ctempfield = EVAL(FIELD(1))   && Get other like records.            WITH oWord               FOR i = 2 TO FCOUNT()                  curfield = EVAL(FIELD(i))                  IF TYPE((FIELD(i)))<>"C"                     DO CASE                     CASE TYPE((FIELD(i))) = "D"                        curfield = DTOC((FIELD(i)))                     CASE TYPE((FIELD(i))) = "N"                        curfield = STR((FIELD(i)))                     CASE TYPE((FIELD(i))) = "Y"                        curfield = STR(EVAL(FIELD(i)),8,2)                     CASE TYPE((FIELD(i))) = "L"                        IF curfield                           curfield = "True"                        ELSE                           curfield = "False"                        ENDIF                     CASE TYPE((FIELD(i))) = "T"                        curfield = TTOC(EVAL(FIELD(i)))                     ENDCASE                     .Selection.TypeText(curfield)                  ELSE                     .Selection.TypeText(curfield)                  ENDIF                     .Selection.MoveRight(12)                  ENDFOR            ENDWITH            SKIP         ENDDO         IF RECNO() > RECCOUNT()   && Prevents an empty table/cells.            EXIT         ELSE            IF newgrouppage               headings_added = .F.    && False: add headings to each page.               oWord.Selection.InsertBreak(2)  && Page break each category.            ENDIF         ENDIF      ENDDO      oWord.Selection.SelectRow   && Ensures no extra rows in the table.      oWord.Selection.Rows.Delete      * This section underlines or turns off all lines in the table.      nanswer = MESSAGEBOX("Turn off underlines Y/N",36,;         "No underlines in the table?")      DO CASE      CASE nanswer = 6       && Yes, turn off all underlines.         WAIT WINDOW 'Formating table with no underlines in the table.';            NOWAIT         WITH oWord            For Each aTable In .ActiveDocument.Tables && Format all tables.               aTable.Borders(-1).LineStyle = 0         && Top border.               aTable.Borders(-2).LineStyle = 0         && Left               aTable.Borders(-3).LineStyle = 0         && Bottom               aTable.Borders(-4).LineStyle = 0         && Right               aTable.Borders(-5).LineStyle = 0         && Horizontal               aTable.Borders(-6).LineStyle = 0         && Vertical               aTable.Borders.Shadow = 0            ENDFOR         ENDWITH      CASE nanswer = 7         && Number just underlines.         WITH oWord            WAIT WINDOW 'Formating table with underlines between records.';               NOWAIT            For Each aTable In .ActiveDocument.Tables && Format each table.               aTable.Borders(-1).LineStyle = 0         && Top border               aTable.Borders(-2).LineStyle = 0         && Left               aTable.Borders(-3).LineStyle = 1         && Bottom               aTable.Borders(-4).LineStyle = 0         && Right               aTable.Borders(-5).LineStyle = 1         && Horizontal               aTable.Borders(-6).LineStyle = 0         && Vertical               aTable.Borders.Shadow = 0            ENDFOR         ENDWITH         oWord.ActiveWindow.View.TableGridlines = .F. && No table gridlines      ENDCASE   * Get the number of pages in the Word report. The code adds the report   * headings to the document header when the user chooses not to have the   * report categories print on separate pages. Makes viewing groups   * headings easier on other pages.      numpages = oWord.ActiveDocument.ComputeStatistics(2)      IF numpages > 1 AND NOT newgrouppage         WITH oWord            .Selection.MoveDown            .ActiveWindow.ActivePane.View.Type = 3 && Put Word in Page view            .ActiveWindow.ActivePane.View.SeekView = 9      && Open header.            .Selection.ParagraphFormat.TabStops.ClearAll   && Clear tabs.            * Printed header width is computed by subtracting margins            * from page width. The margins are divided by 72. Word stores            * these values as points; i.e. 72points/inch.            pagewidth = 8.5-(.ActiveDocument.PageSetup.RightMargin+;            .ActiveDocument.PageSetup.LeftMargin)/72            tabspace = (pagewidth/(numcols))*72 && Convert inches to points            tabstops = tabspace            FOR i = 2 TO FCOUNT()               .Selection.Font.Italic = .T.   && Format heading captions.               .Selection.ParagraphFormat.Alignment = 1               .Selection.Font.Name = "Times New Roman"               .Selection.Font.Size = 8               .Selection.TypeText((FIELD(i)))               .Selection.TypeText(chr(9)) && Tab to set the next heading.               .Selection.ParagraphFormat.TabStops.Add(tabstops) && Tab               tabstops = tabstops+tabspace            ENDFOR         ENDWITH      ENDIF      WITH oWord         .ActiveWindow.View.Type = 3 && Switch to page view. Normal view=1         .ActiveWindow.ActivePane.View.SeekView = 0 && Open main document.         .Selection.Homekey(6)               && Go to top of document.         .Visible = .T.                     && Make Word visible.         .Application.Activate               && Bring Word forward.         .WindowState = 0    && Show Word in normal state. Maximized=1         .ActiveWindow.ActivePane.View.ShowAll = 0 && No nonprinting items.      ENDWITH   ELSE      =MESSAGEBOX("There were no records in the query.",16,;         "Empty Query")   ENDIF   */ End program code /*				
参考
如需有關取得版本 Word 為 Windows 97 更新服務-1,請參閱 「 Microsoft 知識庫 」 中下列文:
172475如何取得並安裝 MS Office 97 SR-1
Microsoft Word Visual Basic 說明

(c) [Microsoft Corporation 1998 年,[保留所有的權限]。 由 Dean Christopher,Microsoft 公司所佔的比重

警告:本文為自動翻譯

內容

文章識別碼:180901 - 最後檢閱時間:02/22/2014 17:32:32 - 修訂: 2.4

Microsoft Visual FoxPro 5.0 Standard Edition, Microsoft Visual FoxPro 5.0a, Microsoft Visual FoxPro 6.0 Professional Edition, Microsoft Visual FoxPro 7.0 Professional Edition, Microsoft Visual FoxPro 8.0 Professional Edition, Microsoft Visual FoxPro 9.0 Professional Edition, Microsoft Word 97 Service Pack 1, Microsoft Office Word 2003

  • kbnosurvey kbarchive kbmt kbcode kbhowto kbinterop KB180901 KbMtzh
意見反應