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 アプリを使用しているため、最後の行は異なります。