共用方式為


HOW TO:在文件中隱藏文字

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 文件層級專案

  • 應用程式層級專案

Microsoft Office 版本

  • Word 2003

  • Word 2007

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

您可以對文字的特定範圍設定 FontHidden 屬性,以隱藏文件中的文字。

例如,您可以暫時隱藏 Microsoft.Office.Tools.Word.Bookmark (文件層級自訂) 或 Microsoft.Office.Interop.Word.Bookmark (應用程式層級增益集) 內的文字,再將文件傳送至印表機。

若要在列印文件時隱藏 Bookmark 控制項中的文字

  1. 建立程序,隱藏所指定範圍的所有文字。

    Shared Sub HideText(ByVal rng As Word.Range)
        rng.Font.Hidden = True
    End Sub
    
    static void HideText(Word.Range rng)
    {
        rng.Font.Hidden = 1;  // 1 = True
    }
    
  2. 建立程序,取消隱藏所指定範圍的所有文字。

    Shared Sub UnhideText(ByVal rng As Word.Range)
        rng.Font.Hidden = False
    End Sub
    
    static void UnhideText(Word.Range rng)
    {
        rng.Font.Hidden = 0;  // 0 = False
    }
    
  3. 將書籤範圍傳遞給 HideText方法、列印文件,然後將相同範圍傳遞給 UnhideText 方法。

    下列程式碼範例可以用於文件層級自訂中。若要使用這個範例,請從專案中的 ThisDocument 類別中執行。

    HideText(Bookmark1.Range)
    
    Me.PrintOut()
    
    UnhideText(Bookmark1.Range)
    
    HideText(bookmark1.Range);
    
    object oTrue = true;
    object oFalse = false;
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object copies = "1";
    object pages = "";
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    
    UnhideText(bookmark1.Range);
    

    下列程式碼範例可以用於應用程式層級的增益集中。本範例使用主動式文件。若要使用這個範例,請從專案中的 ThisAddIn 類別中執行。

    HideText(Bookmark1.Range)
    Me.Application.ActiveDocument.PrintOut()
    UnhideText(Bookmark1.Range)
    
    HideText(bookmark1.Range);
    
    object oTrue = true;
    object oFalse = false;
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object copies = "1";
    object pages = "";
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    
    this.Application.ActiveDocument.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    
    UnhideText(bookmark1.Range);
    

編譯程式碼

這個程式碼範例假設文件包含名稱為 bookmark1 的 Microsoft.Office.Tools.Word.Bookmark 控制項 (文件層級自訂) 或 Microsoft.Office.Interop.Word.Bookmark 控制項 (應用程式層級增益集)。

請參閱

工作

HOW TO:列印文件

HOW TO:在文件中定義及選取範圍

HOW TO:在 Word 文件中重設範圍

HOW TO:更新書籤文字

概念

了解 Office 方案中的選擇性參數