Obtenga el ancho y la altura del papel desde la configuración de la página de la hoja de trabajo
Contents
[
Hide
]
Posibles escenarios de uso
A veces, necesita saber el ancho y el alto del tamaño del papel tal como se configuró en la configuración de página de la hoja de trabajo. Por favor use elPageSetup.PaperWidth yPageSetup.PaperHeightpropiedades para este fin.
Obtenga el ancho y la altura del papel desde la configuración de la página de la hoja de trabajo
El siguiente código de ejemplo explica el uso dePageSetup.PaperWidth yPageSetup.PaperHeightpropiedades. Primero cambia el tamaño del papel a A2 y luego encuentra el ancho y la altura del papel, luego lo cambia a A3, A4, Carta y encuentra el ancho y la altura del papel respectivamente.
Código de muestra
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()); |
Salida de consola
Aquí está la salida de la consola del código de muestra anterior.
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11.0