You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ReportDocument.ReportSource只读无法赋值的问题求助

解决CrystalReport导出PDF时ReportSource只读报错问题

问题原因

你遇到的报错Property or Indexer 'ReportDocument.reportSource'cannot be assigned to -- it is read only,是因为VacuumByDayCrystalReport1的类型为ReportDocument,而该类的ReportSource属性是只读的,无法直接赋值。

解决方法

方法一:仅导出PDF(无需界面显示报表)

如果你的需求只是导出PDF,不需要在界面展示报表,直接移除报错的两行代码即可——导出操作仅依赖你已创建并加载好的cryRpt实例。修改后的代码如下:

ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"C:\temp\ExportVacumeren\ExportVacumeren.rpt");

cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\temp\ExportVacumeren\" + Global.Day + " - " + Global.JaWe + " Vacumeren.pdf");
MessageBox.Show("Exported Vacumeren Successful");

方法二:需显示报表后再导出

如果需要先在界面显示报表再执行导出,需确认VacuumByDayCrystalReport1是CrystalReportViewer控件(而非ReportDocument实例):

  • 若它是CrystalReportViewer控件,直接赋值ReportSource即可(该控件的ReportSource属性是可写的);
  • 若它确实是ReportDocument实例,直接使用它加载报表并执行导出,无需额外创建cryRpt:
VacuumByDayCrystalReport1.Load(@"C:\temp\ExportVacumeren\ExportVacumeren.rpt");
VacuumByDayCrystalReport1.Refresh();
VacuumByDayCrystalReport1.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\temp\ExportVacumeren\" + Global.Day + " - " + Global.JaWe + " Vacumeren.pdf");
MessageBox.Show("Exported Vacumeren Successful");

内容的提问来源于stack exchange,提问作者Ronald Roenhorst

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 08:54:22