如何使用C#更改Crystal报表中的图像(它的OLE对象)?
答案 0 :(得分:2)
您可以将CRAXDRT.dll和CrystalDecisions.Shared.dll添加到您的引用中 然后你可以使用这段代码:
CRAXDRT.Report report2 = new CRAXDRT.Report();
CRAXDRT.Application app2 = new CRAXDRT.Application();
report2 = app2.OpenReport("YourReportName.rpt", OpenReportMethod.OpenReportByDefault);
for (int i = 1; i < report2.Sections.Count + 1; i++)
{
for (int j = 1; j < report2.Sections[i].ReportObjects.Count + 1; j++)
{
try
{
CRAXDRT.OleObject to2 = (CRAXDRT.OleObject)report2.Sections[i].ReportObjects[j];
CRAXDRT.OleObject to3 = report2.Sections[i].AddPictureObject("NewOleName.bmp", to2.Left, to2.Top);
to3.Height = to2.Height;
to3.Width = to2.Width;
report2.Sections[i].DeleteObject(to2);
}
catch (Exception) { }
}
}
答案 1 :(得分:1)
假设您的图像位于Bitmap对象中,
以Bitmap格式将其保存到MemoryStream,
创建一个DataSource,使用1个DataColumn创建DataTable,其类型为字节数组
MemoryStream ms; //contains saved bitmap~!!!
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("img", typeof(Byte[])));
DataRow row = dt.NewRow();
row["img"] = ms.ToArray();
还将报告(或报告的子报告)绑定到具有上述模式的DataSource 插入绑定到“img”列的图像对象以进行报告