Workbook.PrintOut 方法

列印活頁簿。

命名空間:  Microsoft.Office.Tools.Excel
組件:   Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

語法

'宣告
Sub PrintOut ( _
    From As Object, _
    To As Object, _
    Copies As Object, _
    Preview As Object, _
    ActivePrinter As Object, _
    PrintToFile As Object, _
    Collate As Object, _
    PrToFileName As Object _
)
void PrintOut(
    Object From,
    Object To,
    Object Copies,
    Object Preview,
    Object ActivePrinter,
    Object PrintToFile,
    Object Collate,
    Object PrToFileName
)

參數

  • From
    型別:System.Object
    要開始列印的頁碼。如果省略這個引數,則會從頭開始列印。
  • To
    型別:System.Object
    要列印的最後一頁的頁碼。如果省略這個引數,則會列印到最後一頁。
  • Copies
    型別:System.Object
    要列印的份數。如果省略這個引數,則會列印一份報表。
  • Preview
    型別:System.Object
    true 表示會讓 Microsoft Office Excel 在列印物件之前叫用預覽列印。false 則表示會立即列印物件。
  • ActivePrinter
    型別:System.Object
    設定作用中印表機的名稱。
  • PrintToFile
    型別:System.Object
    true 表示列印至檔案。如果未指定 PrToFileName,則 Excel 會提示使用者輸入輸出檔的名稱。
  • Collate
    型別:System.Object
    true 表示列印多份複本並自動分頁。
  • PrToFileName
    型別:System.Object
    如果 PrintToFile 設定為 true,則這個引數會指定您想要列印至 (檔案) 的檔案名稱。

備註

From 和 To 欄位中的「頁」是指列印的頁面,不是指工作表或活頁簿的整體頁面。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例使用 PrintOut 方法,將目前活頁簿的頭兩張列印頁面用印表機列印一份。

Private Sub WorkbookPrintOutPrinter()
    ' Add a range value to make sure that the workbook prints.
    ' An empty workbook will not be printed.
    Globals.Sheet1.Range("A1", "A5").Value2 = 55
    Me.PrintOut(1, 2, 1, False, "HP17642", False, False)
End Sub
private void WorkbookPrintOutPrinter()
{
    // Add a range value to make sure that the workbook prints.
    // An empty workbook will not be printed.
    Globals.Sheet1.Range["A1", "A5"].Value2 = 55;
    this.PrintOut(1, 2, 1, false, "HP17642", false, false);
}

下列程式碼範例使用 PrintOut 方法,將目前活頁簿的頭兩張列印頁面列印一份至名為 C:\MyData.xls 的檔案。

Private Sub WorkbookPrintOutFile()
    ' Add a range value to make sure that the workbook prints.
    ' An empty workbook will not be printed.
    Globals.Sheet1.Range("A1", "A5").Value2 = 55
    Me.PrintOut(1, 2, 1, False, PrintToFile:=True, Collate:=False, _
        PrToFileName:="c:\MyData.xlsx")
End Sub
private void WorkbookPrintOutFile()
{
    // Add a range value to make sure that the workbook prints.
    // An empty workbook will not be printed.
    Globals.Sheet1.Range["A1", "A5"].Value2 = 55;
    this.PrintOut(1, 2, 1, false, true, false,
        @"C:\MyData.xlsx");
}

.NET Framework 安全性

請參閱

參考

Workbook 介面

Microsoft.Office.Tools.Excel 命名空間