如何在C#中以编程方式检索Crystal页面设置?(How to retrieve Crystal page setting programmatically in C#?)

329 IT屋

I created a Crystal report (.rpt file) in Crystal Designer. I configured Page Setup. I want to retrieve e.g. page orientation, page width, page high programmatically in C#. How to do it? Note that I want to retrieve page settings, no print settings. I don't want to edit page settings, I only need to read it.

===EDIT===

Following figure shows my page setup:

enter image description here

PrintOptions.PageContentWidth and PrintOptions.PageContentHeight in C# have different values.

ReportDocument rp = new ReportDocument();
rp.Load(path_to_my_report_file);
Console.WriteLine(rp.PrintOptions.PageContentHeight);
Console.WriteLine(rp.PrintOptions.PageContentWidth);

Output:

5670
8505

I need to retrieve page width and height to set they in PaperSize (myPaperSize = new System.Drawing.Printing.PaperSize(name, width, height);)

解决方案

ReportDocument.PrintOptions should give you the numbers that you need. For example, for the page width, using members of PrintOptions:

PageContentWidth + PageMargins.leftMargin + PageMargins.rightMargin

However, these values are in TWIPS, where 1440 twips = 1 inch. (I have no idea what the proper capitalization is...)


On the other hand, System.Drawing.Printing.PaperSize uses numbers in hundredths of an inch, so you would have to convert:

[Dimension in hundredths of an inch] = [Dimension in TWIPS] / 1440.0 * 100

我在Crystal Designer中创建了一个Crystal报表(.rpt文件)。我配置了页面设置。我想要检索页面方向,页面宽度,页面高编程方式在C#。怎么做?注意,我想检索页面设置,没有打印设置。我不想编辑页面设置,我只需要阅读它。



=== EDIT ===



下图显示了我的页面设置:



enter image description here



PrintOptions.PageContentWidth 和 C#中的PrintOptions.PageContentHeight 有不同的值。



  ReportDocument rp = new ReportDocument(); 
rp.Load(path_to_my_report_file);
Console.WriteLine(rp.PrintOptions.PageContentHeight);
Console.WriteLine(rp.PrintOptions.PageContentWidth);


输出:



 code> 5670 
8505


我需要检索页面宽度和高度他们在PaperSize( myPaperSize = new System.Drawing.Printing.PaperSize(name,width,height); )


解决方案

ReportDocument.PrintOptions 应该给你所需要的数字。例如,对于页面宽度,使用 PrintOptions 的成员:



  PageContentWidth + PageMargins.leftMargin + PageMargins.rightMargin 


TWIPS (其中 1440 twips = 1英寸)中。 (我不知道适当的大写是什么...)






另一方面, System.Drawing.Printing.PaperSize 使用百分之一英寸的数字,因此您必须转换:



  [以百分之一英寸为单位的尺寸] = [以TWIPS为单位的尺寸] / 1440.0 * 100 

本文地址:IT屋 » 如何在C#中以编程方式检索Crystal页面设置?