Aspose.Cells で印刷時にジョブまたはドキュメント名を指定する
Contents
[
Hide
]
WorkbookRender や SheetRender オブジェクトを使用してワークブックやワークシートを印刷する際にジョブまたはドキュメント名を指定することができます。Aspose.Cells は、指定したジョブ名を使用してワークブックやワークシートを印刷するための WorkbookRender.ToPrinter(printerName, jobName) および SheetRender.ToPrinter(printerName, jobName) メソッドを提供しています。
Aspose.Cellsを使用して印刷時にジョブまたは文書名を指定する
サンプルコードは、元のExcelファイルをロードし、WorkbookRender.ToPrinter(printerName、jobName)およびSheetRender.ToPrinter(printerName、jobName)メソッドを使用してジョブまたは文書名を指定して印刷用に送信します。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
string printerName = ""; | |
while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName)) | |
{ | |
Console.WriteLine("Please Enter Your Printer Name:"); | |
printerName = Console.ReadLine(); | |
} | |
string jobName = "Job Name while Printing with Aspose.Cells"; | |
// Print workbook using WorkbookRender | |
WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions()); | |
try | |
{ | |
wr.ToPrinter(printerName, jobName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Print worksheet using SheetRender | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
try | |
{ | |
sr.ToPrinter(printerName, jobName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |