0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#でSpire.XLS for .NETを使用してExcelファイルをサイレント印刷する

Posted at

1. はじめに

  • Excelファイルをサイレント印刷したい
  • Spire.XLS for .NETを使用して実行したい

2. 動作環境

  • C#
  • .NET 8
  • Spire.XLS for .NET
  • Visual Stduio 2022
  • Windows 11

3. Spire.XLS for .NETとは

  • E-ICEBLUE社が開発したExcel の文書ファイルを迅速かつ高品質で作成・編集・変換・印刷するために設計された専門的な Excel.NET ライブラリです。

4. サンプルソース

  • ホームページあるサンプルを実行するだけで簡単に動いた
Program.cs
using Spire.Xls;
using System.Drawing.Printing;

namespace SilentlyPrint
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // ワークブックオブジェクトを作成
                Workbook workbook = new Workbook();

                // Excelファイルをロード
                workbook.LoadFromFile(@"C:\Sample.xlsx");

                // 印刷プロセスを表示しないようにStandardPrintControllerを設定
                workbook.PrintDocument.PrintController = new StandardPrintController();

                // ワークブックからPrinterSettingsを取得
                PrinterSettings settings = workbook.PrintDocument.PrinterSettings;

                // プリンタ名、両面印刷モード、および印刷ページを指定
                settings.PrinterName = "プリンタ名";

                // ワークブックを印刷
                workbook.PrintDocument.Print();
            }
            catch (Exception e)
            {
                // エラー処理
            }
        }
    }
}

5. 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?