0

Visual Studio 2010 SAP Crystal Reports を使用しています。
レポート ビューアーを使用してフォームをセットアップし、カスタム デザインの rpt ファイルをビューアーのソースに読み込みます。
それは正常に動作します。
次のように、コード ビハインドから rpt ファイルのカスタム設計フィールドを変更することもできます。

ReportDocument reportDocument = new ReportDocument();

string filePath = AppDomain.CurrentDomain.BaseDirectory; 

filePath = filePath.Replace("bin\\Debug\\", "MyReportClass.rpt");

reportDocument.Load(filePath);

CrystalDecisions.CrystalReports.Engine.TextObject MyText1= ((CrystalDecisions.CrystalReports.Engine.TextObject)reportDocument.ReportDefinition.Sections[3].ReportObjects["MyText1"]);

MyText1.Text = "Test Work";

MyReportViewer.ReportSource = reportDocument;

質問:コード ビハインドで ReportDocument に新しい TextObject を追加するにはどうすればよいですか?

私が試してみました:

reportDocument.Sections(2).AddTextObject(..

しかし、その方法は存在しません

4

1 に答える 1

0

Crystal Reports TextObject はそれほど単純ではありません。最初に ParagraphTextElement を作成し、それを ParagraphElements オブジェクト内の Paragraphs オブジェクト内の Paragraph オブジェクトに配置し、そのオブジェクトを TextObject.Paragraphs プロパティに割り当てる必要があります。

次に、ReportDefinition でレポートのセクションを見つけて追加し、ReportDefinition を介してそのオブジェクトをセクションに追加する必要があります。

説明は十分ですが、これが私の using ステートメントです。

#region Using

using System;
using System.Windows;

using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;

#endregion

そして、これが私がそれを動かしたコードです:

var reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

var filePath = AppDomain.CurrentDomain.BaseDirectory;
filePath = filePath.Replace("bin\\Debug\\", "MyReport.rpt");
reportDocument.Load(filePath);

ReportDefController2 reportDefinitionController = reportDocument.ReportClientDocument.ReportDefController;

ISCRParagraphTextElement paraTextElementClass = new ParagraphTextElement { Text = "Text Work", Kind = CrParagraphElementKindEnum.crParagraphElementKindText };

ParagraphElements paragraphElements = new ParagraphElements();
paragraphElements.Add(paraTextElementClass);

Paragraph paragraph = new Paragraph();
paragraph.ParagraphElements = paragraphElements;

Paragraphs paragraphs = new Paragraphs();
paragraphs.Add(paragraph);

TextObject newTextObject = new TextObject();
newTextObject.Paragraphs = paragraphs;

var detailSection = reportDefinitionController.ReportDefinition.DetailArea.Sections[0];
reportDefinitionController.ReportObjectController.Add(newTextObject, detailSection, 0);

// MyReportViewer.ReportSource = reportDocument;
this.crystalReportsViewer.ViewerCore.ReportSource = reportDocument;

テストを行うために WPF アプリを使用しているため、最後の行は異なります。

于 2014-03-03T07:22:15.677 に答える