Çalışma Kitaplarını Yazdırma
Kullanım Senaryosu
Elektronik tablonuzu oluşturmayı bitirdikten sonra, ihtiyaçlarınız için büyük olasılıkla sayfanın basılı bir kopyasını yazdırmak isteyeceksiniz. Yazdırırken, seçiminizi belirtmediğiniz sürece, MS Excel tüm çalışma sayfası alanını yazdırmak istediğinizi varsayar. Aşağıdaki ekran görüntüsü, çalışma kitabını Excel ile yazdırmak için iletişim kutusunu gösterir.
Figür: Yazdır İletişim Kutusu
Aspose.Cells kullanarak Çalışma Kitaplarını Yazdırma
Aspose.Cells for Java sağlaryazıcıya yöntemiSheetRender sınıf. kullanarakSheetRender.toPrinter yönteminde, yazdırma işi adının yanı sıra yazıcı adını da sağlayabilirsiniz.
Basit kod
Seçilen Çalışma Sayfasını Yazdır
Aşağıdaki kod parçacığı,SheetRender.toPrinter yöntemi, seçtiğiniz çalışma sayfasını yazdırmak için.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(PrintingSelectedWorksheet.class); | |
// Instantiate a new workbook | |
Workbook book = new Workbook(dataDir + "Book1.xls"); | |
// Create an object for ImageOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Create a SheetRender object with respect to your desired sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
// Print the worksheet | |
sr.toPrinter(strPrinterName); |
Tüm Çalışma Kitabını Yazdır
Şunu da kullanabilirsiniz:WorkbookRender.toPrinter tüm çalışma kitabını yazdırma yöntemi. Aşağıdaki kod parçacığı,WorkbookRender.toPrinter tüm çalışma kitabını yazdırma yöntemi.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(PrintingWholeWorkbook.class); | |
// Instantiate a new workbook | |
Workbook book = new Workbook(dataDir + "Book1.xls"); | |
// Create an object for ImageOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// WorkbookRender only support TIFF file format | |
imgOptions.setImageFormat(ImageFormat.getTiff()); | |
// Create a WorkbookRender object with respect to your workbook | |
WorkbookRender wr = new WorkbookRender(book, imgOptions); | |
// Print the workbook | |
wr.toPrinter(strPrinterName); |