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

可能な使用シナリオ

時々、ワークシートのページ設定で設定された用紙サイズの幅と高さを知る必要があります。この場合は、PageSetup.PaperWidth プロパティおよび PageSetup.PaperHeight プロパティを使用してください。

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

以下のサンプルコードは、PageSetup.PaperWidth プロパティと PageSetup.PaperHeight プロパティの使用方法を説明しています。まず用紙サイズを A2 に変更し、次に用紙の幅と高さを見つけ、その後それぞれを A3A4Letter に変更して、用紙の幅と高さを見つけます。

サンプルコード

// 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