Stampa di cartelle di lavoro
Scenario di utilizzo
Dopo aver finito di creare il tuo foglio di calcolo, probabilmente vorrai stampare una copia cartacea del foglio per le tue necessità. Quando si stampa, MS Excel presuppone che si desideri stampare l’intera area del foglio di lavoro a meno che non si specifichi la selezione. Lo screenshot seguente mostra la finestra di dialogo per la stampa della cartella di lavoro con Excel.
Figura: Finestra di dialogo Stampa
Stampa di cartelle di lavoro utilizzando Aspose.Cells
Aspose.Cells for Java fornisce atoPrinter metodo delFoglioRendering classe. Utilizzando ilSheetRender.toPrinter, è possibile fornire il nome della stampante oltre al nome del processo di stampa.
Codice d’esempio
Stampa foglio di lavoro selezionato
Il seguente frammento di codice illustra l’uso diSheetRender.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); |
Stampa intera cartella di lavoro
Puoi anche usare ilWorkbookRender.toPrinter metodo per stampare l’intera cartella di lavoro. Il seguente frammento di codice illustra l’uso diWorkbookRender.toPrinter metodo per stampare l’intera cartella di lavoro.
// 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); |