ワークシートの PageSetup から用紙の幅と高さを取得する
Contents
[
Hide
]
考えられる使用シナリオ
ワークシートのページ設定で用紙サイズが設定されているため、用紙サイズの幅と高さを知る必要がある場合があります。をご利用くださいPageSetup.PaperWidthとPageSetup.PaperHeightこの目的のためのプロパティ。
ワークシートの PageSetup から用紙の幅と高さを取得する
次のサンプル コードは、PageSetup.PaperWidthとPageSetup.PaperHeightプロパティ。最初に用紙サイズを A2 に変更し、次に用紙の幅と高さを見つけ、次にそれを A3、A4、レターに変更して、それぞれ用紙の幅と高さを見つけます。
サンプルコード
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()); |
コンソール出力
上記のサンプル コードのコンソール出力を次に示します。
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11.0