ページヘッダーとフッターの操作

MPPファイルからヘッダーおよびフッター情報を読み取る

Aspose.Tasks for .NET API は MPPファイルからヘッダーおよびフッター情報を読み取る機能を提供します。API には各タブに対応する専用のクラスが含まれます。 Microsoft Project Page Setup ダイアログ:

次の例は MPPファイルからヘッダーおよびフッター情報を読み取る方法を示します:

 1static void Run()
 2{
 3    // Create project and project info instances
 4    Project project = new Project("New Project.mpp");
 5    PageInfo info = project.DefaultView.PageInfo;
 6
 7    Console.WriteLine("Page data cannot be null : {0} ", !info.Equals(null));
 8
 9    if (info != null)
10    {
11        AssertHeaderFooterCorrect(info);
12        AssertPageSettingsCorrect(info);
13        AssertPageViewSettingsCorrect(info);
14        AssertMarginsCorrect(info);
15        AssertLegendCorrect(info);
16    }
17 
18}
19
20static void AssertHeaderFooterCorrect(PageInfo info)
21{
22    Console.WriteLine("Header left text Equals LEFT HEADER : {0} ", info.Header.LeftText.Equals("LEFT HEADER"));
23    Console.WriteLine("Header center text Equals CENTER HEADER : {0} ", info.Header.CenteredText.Equals("CENTER HEADER"));
24    Console.WriteLine("Header right text Equals RIGHT HEADER : {0} ", info.Header.RightText.Equals("RIGHT HEADER"));
25
26    Console.WriteLine("Footer left text Equals LEFT FOOTER : {0} ", info.Footer.LeftText.Equals("LEFT FOOTER"));
27    Console.WriteLine("Footer center text Equals CENTER FOOTER : {0} ", info.Footer.CenteredText.Equals("CENTER FOOTER"));
28    Console.WriteLine("Footer right text Equals RIGHT FOOTER : {0} ", info.Footer.RightText.Equals("RIGHT FOOTER"));
29}
30
31static void AssertPageSettingsCorrect(PageInfo info)
32{
33    Console.WriteLine("Portrait Orientation is Portrait : {0} ", info.PageSettings.IsPortrait.Equals(true));
34    Console.WriteLine("AdjustToPercentOfNormalSize is enabled : {0} ", info.PageSettings.AdjustToPercentOfNormalSize.Equals(true));
35 
36    Console.WriteLine("PercentOfNormalSize Equals 150 : {0} ", info.PageSettings.PercentOfNormalSize.Equals(150));
37    Console.WriteLine("PagesInWidth Equals 3 : {0} ", info.PageSettings.PagesInWidth.Equals(3));
38    Console.WriteLine("PagesInHeight Equals 7 : {0} ", info.PageSettings.PagesInHeight.Equals(7));
39    Console.WriteLine("PaperSize Equals PaperA4 : {0} ", info.PageSettings.PaperSize.Equals(PrinterPaperSize.PaperA4));
40    Console.WriteLine("FirstPageNumber : {0} ", info.PageSettings.FirstPageNumber);
41}
42
43static void AssertPageViewSettingsCorrect(PageInfo info)
44{
45    Console.WriteLine("PrintAllSheetColumns is set to false : {0} ", info.PageViewSettings.PrintAllSheetColumns.Equals(false));
46    Console.WriteLine("PrintFirstColumnsCountOnAllPages is set to true : {0} ", info.PageViewSettings.PrintFirstColumnsCountOnAllPages.Equals(true));
47
48    Console.WriteLine("FirstColumnsCount Equals 3 : {0} ",  info.PageViewSettings.FirstColumnsCount.Equals(3));
49    Console.WriteLine("PrintNotes is set to true : {0} ", info.PageViewSettings.PrintNotes.Equals(true));
50    Console.WriteLine("PrintBlankPages is set to false : {0} ", info.PageViewSettings.PrintBlankPages.Equals(false));
51    Console.WriteLine("FitTimescaleToEndOfPage is set to true : {0} ", info.PageViewSettings.FitTimescaleToEndOfPage.Equals(true));
52}
53
54static void AssertMarginsCorrect(PageInfo info)
55{
56    Console.WriteLine("Margins.Left Equals 1 : {0} ", (info.Margins.Left - 1 <= 1e-5) ? true : false);
57    Console.WriteLine("Margins.Top Equals 1.1 : {0} ", (info.Margins.Top - 1.1 <= 1e-5) ? true : false);
58    Console.WriteLine("Margins.Right Equals 1.2 : {0} ", (info.Margins.Right - 1.2 <= 1e-5) ? true : false);
59    Console.WriteLine("Margins.Bottom Equals 1.2 : {0} ", (info.Margins.Bottom - 1.3 <= 1e-5) ? true : false);
60
61    Console.WriteLine("Margin.Borders Equals Border.AroundEveryPage : {0} ",info.Margins.Borders.Equals(Border.AroundEveryPage));
62}
63
64static void AssertLegendCorrect(PageInfo info)
65{
66    Console.WriteLine("Legend left text Equals LEFT LEGEND : {0} ", info.Legend.LeftText.Equals("LEFT LEGEND"));
67    Console.WriteLine("Legend center text Equals CENTER LEGEND : {0} ", info.Legend.CenteredText.Equals("CENTER LEGEND"));
68    Console.WriteLine("Legend right text Equals RIGHT LEGEND : {0} ", info.Legend.RightText.Equals("RIGHT LEGEND"));
69
70    Console.WriteLine("LegendOn Equals Legend.OnEveryPage : {0} ", info.Legend.LegendOn.Equals(Legend.OnEveryPage));
71    Console.WriteLine("Legend Width Equals 5 : {0} ", (info.Legend.Width - 5 <= 1e-5) ? true : false);
72}

ページのヘッダーおよびフッターに画像を追加

Aspose.Tasks for .NET は、画像の挿入を含むページのヘッダーおよびフッターの操作機能も提供します。以下の例は、ページヘッダーに画像を追加する方法を示します:

 1Project project = new Project("New Project.mpp");
 2
 3project.RootTask.Children.Add("Task1");
 4PageInfo pageInfo = project.DefaultView.PageInfo;
 5
 6using (Image image = Image.FromFile("Image1.png"))
 7{
 8    pageInfo.Header.CenteredImage = image;
 9    pageInfo.Legend.LeftImage = image;
10    pageInfo.Legend.LeftText = string.Empty;
11    MPPSaveOptions options = new MPPSaveOptions();
12    options.WriteViewData = true;
13    project.Save("AddImageToPageHeaderFooter_out.mpp", options);
14}

Aspose.Tasks for .NET を使用することで、開発者は ページ設定、ヘッダー、フッター、余白、凡例、表示設定を含む。
この柔軟性により、 専門的なレポートおよび印刷レイアウト をプログラムで自動的に作成でき、プロジェクト文書が組織の基準を満たすことを保証し、Microsoft Project での手動調整を不要にします。

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.