Stampa Fogli di lavoro

Scenario d’uso

Dopo aver creato il tuo foglio di calcolo, probabilmente vorrai stampare una copia cartacea della scheda per le tue esigenze. Quando stai stampando, MS Excel presume che tu voglia stampare l’intera area del foglio di lavoro a meno che tu non specifichi la tua selezione. Nella seguente schermata viene mostrata la finestra di dialogo per la stampa del workbook con Excel.

todo:image_alt_text

Figura: Finestra di dialogo di stampa

Stampare i fogli di lavoro con Aspose.Cells

Aspose.Cells for Java fornisce un metodo toPrinter della classe SheetRender. Utilizzando il metodo SheetRender.toPrinter, puoi fornire il nome della stampante e il nome del lavoro di stampa.

Codice di esempio

Stampare il foglio di lavoro selezionato

Il seguente frammento di codice dimostra l’uso del metodo SheetRender.toPrinter per stampare il foglio di lavoro selezionato.

// 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);

Stampare l’intero workbook

Puoi anche utilizzare il metodo WorkbookRender.toPrinter per stampare l’intero workbook. Il seguente frammento di codice dimostra l’uso del metodo WorkbookRender.toPrinter per stampare l’intero workbook.

// 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);

Articoli correlati