ワークシートのページ設定の用紙幅と高さを取得

考えられる使用シナリオ

ワークシートのページ設定で用紙サイズが設定されているため、用紙サイズの幅と高さを知る必要がある場合があります。をご利用くださいPageSetup.PaperWidthPageSetup.PaperHeightこの目的のためのプロパティ。

ワークシートのページ設定の用紙幅と高さを取得

次のサンプル コードは、PageSetup.PaperWidthPageSetup.PaperHeightプロパティ。最初に用紙サイズをA2次に、用紙の幅と高さを見つけて、それを次のように変更しますA3, A4, 手紙用紙の幅と高さをそれぞれ求めます。

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create an instance of Workbook class
Workbook book = new Workbook();
// Access first worksheet
Worksheet sheet = book.Worksheets[0];
// Set paper size to A2 and print paper width and height in inches
sheet.PageSetup.PaperSize = PaperSizeType.PaperA2;
Console.WriteLine("PaperA2: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight);
// Set paper size to A3 and print paper width and height in inches
sheet.PageSetup.PaperSize = PaperSizeType.PaperA3;
Console.WriteLine("PaperA3: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight);
// Set paper size to A4 and print paper width and height in inches
sheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
Console.WriteLine("PaperA4: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight);
// Set paper size to Letter and print paper width and height in inches
sheet.PageSetup.PaperSize = PaperSizeType.PaperLetter;
Console.WriteLine("PaperLetter: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight);

コンソール出力

上記のサンプル コードのコンソール出力を次に示します。

PaperA2: 16.54x23.39

PaperA3: 11.69x16.54

PaperA4: 8.27x11.69

PaperLetter: 8.5x11