Carica la cartella di lavoro con il formato carta della stampante specificato
Contents
[
Hide
]
È possibile specificare il formato della carta della stampante di propria scelta durante il caricamento della cartella di lavoro utilizzando il fileLoadOptions.setPaperSize() metodo. Si prega di notare che, se si crea un nuovo file in MS Excel, si noterà che il formato della carta è lo stesso dell’impostazione della stampante predefinita nella macchina.
Carica la cartella di lavoro con il formato carta della stampante specificato
Il codice di esempio seguente illustra l’utilizzo di[LoadOptions.setPaperSize()](https://reference.aspose.com/cells/java/com.aspose.cells/loadoptions#setPaperSize(int) metodo. Prima crea una cartella di lavoro, quindi la salva in un flusso di array di byte nel formato XLSX. Quindi lo carica con carta formato A5 e lo salva nel formato PDF. Quindi lo carica di nuovo con formato carta A3 e lo salva nuovamente nel formato PDF. Se apri i PDF di output e controlli il loro formato carta, vedrai che sono diversi. Uno è A5 e l’altro è A3. Si prega di scaricare ilA5 uscita PDF eUscita A3 PDF generato dal codice per riferimento.
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(LoadWorkbook.class); | |
// Create a sample workbook and add some data inside the first worksheet | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
worksheet.getCells().get("P30").putValue("This is sample data."); | |
// Save the workbook in memory stream | |
ByteArrayOutputStream baout = new ByteArrayOutputStream(); | |
workbook.save(baout, SaveFormat.XLSX); | |
// Get bytes and create byte array input stream | |
byte[] bts = baout.toByteArray(); | |
ByteArrayInputStream bain = new ByteArrayInputStream(bts); | |
// Now load the workbook from memory stream with A5 paper size | |
LoadOptions opts = new LoadOptions(LoadFormat.XLSX); | |
opts.setPaperSize(PaperSizeType.PAPER_A_5); | |
workbook = new Workbook(bain, opts); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output-a5.pdf"); | |
// Now load the workbook again from memory stream with A3 paper size | |
opts = new LoadOptions(LoadFormat.XLSX); | |
opts.setPaperSize(PaperSizeType.PAPER_A_3); | |
workbook = new Workbook(bain, opts); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output-a3.pdf"); |