طباعة نطاق الصفحات باستخدام SheetRender و WorkbookRender
يسمح Microsoft Excel بطباعة نطاق الصفحات من كتاب العمل أو ورقة العمل. تظهر اللقطة الشاشية التالية واجهة Microsoft Excel لتحديد نطاق الصفحات.
توفر Aspose.Cells طرق WorkbookRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount) و SheetRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount) لهذا الغرض.
واجهة Microsoft Excel لتحديد نطاق الصفحات المراد طباعتها
الشيفرة التالية توضح استخدام WorkbookRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount) و SheetRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount). إنها تطبع الصفحات 2-5 من الكتاب أو الورقة العمل.
// 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 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(); | |
} | |
ImageOrPrintOptions bookRenderOptions = new ImageOrPrintOptions(); | |
bookRenderOptions.PageIndex = 1; | |
bookRenderOptions.PageCount = 2; | |
// Print the worbook specifying the range of pages. Here we are printing pages 2-3 | |
WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions()); | |
try | |
{ | |
wr.ToPrinter(printerName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
ImageOrPrintOptions sheetRenderOptions = new ImageOrPrintOptions(); | |
sheetRenderOptions.PageIndex = 1; | |
sheetRenderOptions.PageCount = 2; | |
// Print the worksheet specifying the range of pages. Here we are printing pages 2-3 | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
try | |
{ | |
sr.ToPrinter(printerName); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |