1

如何使用 C# 在 Crystal 报表中更改图像(其 OLE 对象)?

4

2 回答 2

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) { }
                    }
                }
于 2013-10-06T11:34:16.087 回答
1

Suppose you have your image in a Bitmap object, save it to MemoryStream in Bitmap format,
Create a DataSource, create DataTable in it with 1 DataColumn with type of byte array

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();

also have the report (or subreport of your report) bound to DataSource with schema as above insert Image object bound to the "img" column to report

于 2009-03-03T10:34:41.047 回答