I am developing a WPF application (Visual Studio 2019 V16.11.17) and use CrystalReportsViewer to preview the report with a picture in it. When I click at built-in export button in CrystalReportsViewer and select type "Microsoft Excel (XLSX) (*.xlsx)" and save, the application closed unexpectedly without any error or exception even I already tried to caught unhandled exception. How do I fix this? and how to get error info?
In App.xaml file:
DispatcherUnhandledException="Application_DispatcherUnhandledException"
In App.xaml.cs file:
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show("Error" + Environment.NewLine + e.Exception.Message, "Error");
e.Handled = true;
}
In MainWindow.xaml.cs file:
public MainWindow()
{
InitializeComponent();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Debug.Print(e.ToString());
}
Preview crystal report code:
_report = new ReportDocument();
_report.Load("Path to CrystalReport.rpt");
_report.SetDataSource(dataTable);
ViewerCore view = crystalReportViewer1.ViewerCore;
view.ReportSource = _report;
More information:
Thanks in advance.
It's a limitation of crystal reports that you can only export data only to excel. Pictures, not being data, will result in unpredictable results.
Options include:
Choose one of the export formats that supports pictures, such as pdf
Remove the picture
Use a different reporting provider.
Since crystal reports is not supported in recent versions of visual studio, you might want to consider a different reporting approach now for longer term support.
Please see:
Edit
If your users particularly like their data in reports you could maybe consider excel based reporting and xslt. I had to do this one place I worked back in 2009 to give users spreadsheets with calculations in them. It was easier than I thought ( start with a formatted xslx spreadsheet ). The user departments were very pleased and it's been an approach I've used successfully a few times since.