很多人可能都碰到过,正常预览和打印是没有问题,而把报表导出后再加载的时侯却出现“报表加载失败”的问题,这是由于路径原因导致的。导出报表后,其相对路径就变成了导出位置的路径,除非你关闭程序重新加载,否则无法自动更正。下面是我的解决办法,供大家参考:
//首先取得应用程序的路径 String* strPath=Application::StartupPath; if( strPath->Chars[strPath->Length-1] == '\\') strPath=strPath->Substring(0,strPath->Length-1);
//取得报表路径 String* strReportPath=S""; strReportPath=String::Concat(strPath,S".\\Report\\***.rpt");
CrystalReportViewer* crystalReportView1 = new CrystalReportViewer(); DataSet* DS = new DataSet();
…………… //此处进行数据集填充
ReportDocument* oRpt = new ReportDocument(); oRpt->Load(strReportPath); oRpt->SetDataSource(DS); crystalReportView1->ReportSource = oRpt;
|