Ottieni larghezza e altezza della carta da PageSetup del foglio di lavoro
Contents
[
Hide
]
Possibili scenari di utilizzo
A volte, è necessario conoscere la larghezza e l’altezza del formato della carta poiché è stata impostata nell’impostazione della pagina del foglio di lavoro. Si prega di utilizzare ilPageSetup.PaperWidth ePageSetup.PaperHeightproprietà a questo scopo.
Ottieni larghezza e altezza della carta da PageSetup del foglio di lavoro
Il seguente codice di esempio spiega l’utilizzo diPageSetup.PaperWidth ePageSetup.PaperHeightproprietà. Prima cambia il formato della carta in A2 e poi trova la larghezza e l’altezza della carta, quindi lo cambia in A3, A4, Letter e trova rispettivamente la larghezza e l’altezza della carta.
Codice d’esempio
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 | |
//Create workbook | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Set paper size to A2 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_2); | |
System.out.println("PaperA2: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to A3 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_3); | |
System.out.println("PaperA3: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to A4 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4); | |
System.out.println("PaperA4: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to Letter and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_LETTER); | |
System.out.println("PaperLetter: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); |
Uscita console
Ecco l’output della console del codice di esempio precedente.
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11.0