Crystal 报告导出崩溃 C#
本文关键字:崩溃 报告 Crystal | 更新日期: 2023-09-27 18:32:11
我在将水晶报告导出为PDF时遇到了一些问题。我的程序在 teleneUdaje.rpt 的负载下崩溃,我是舒尔,这是正确的名称。
如果(txtpath.Text == ") throw new Exception("Prosím zvoľte cieľovú adresu");
DataSet dt = new DataSet();
string x = nastavenia.adresa_servera();
string y = nastavenia.nazov_databazy();
string z = nastavenia.ponechat_udaje();
string a = nastavenia.sql_meno();
string b = nastavenia.sql_heslo();
SqlConnection databaza = new SqlConnection();
databaza.ConnectionString = "Data Source=" + x + ";Initial Catalog=" + y + ";Persist Security Info=" + z + ";User ID=" + a + "; password=" + b + "";
da.SelectCommand = new SqlCommand("SELECT * FROM tblTepelneUdaje", databaza);
dt.Clear();
da.Fill(dt);
System.IO.FileInfo info = new System.IO.FileInfo(txtpath.Text.Trim());
string type = info.Extension;
CrystalDecisions.Shared.ExportFormatType tp = CrystalDecisions.Shared.ExportFormatType.Excel;
switch (type)
{
case ".pdf":
tp = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case ".doc":
tp = CrystalDecisions.Shared.ExportFormatType.WordForWindows; break;
case ".rtf":
tp = CrystalDecisions.Shared.ExportFormatType.RichText; break;
case ".xls":
tp = CrystalDecisions.Shared.ExportFormatType.Excel; break;
default: MessageBox.Show("Invalid File type you entered"); break;
}
ReportDocument doc = new ReportDocument();
doc.Load("TeleneUdaje.rpt");
doc.SetDataSource(dt);
doc.ExportToDisk(tp, txtpath.Text);
MessageBox.Show("Zostava bola úspešne exportovaná");
请帮忙。
**编辑
它会引发水晶报告异常,指出报告加载失败。该文件是正常的,因为在程序中,我可以使用报告查看器工具显示报告。
我找到了我问题的正确答案。表达式
doc.Load("TeleneUdaje.rpt")
是错误的,因为它需要 .rpt 文件的完整路径,如下所示:
doc.Load("C:''report.rpt");
感谢评论伙计们