WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

huangapple go评论67阅读模式
英文:

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

问题

在你提供的内容中,以下是已翻译的部分:

  • 我正在开发一个 WPF 应用程序(Visual Studio 2019 V16.11.17),并使用 CrystalReportsViewer 预览带有图片的报表。当我单击 CrystalReportsViewer 中的内置导出按钮并选择类型 "Microsoft Excel (XLSX) (*.xlsx)" 并保存时,应用程序会突然关闭,没有任何错误或异常,即使我已经尝试捕获未处理的异常。我该如何修复这个问题?以及如何获取错误信息?

  • 在 App.xaml 文件中:

DispatcherUnhandledException="Application_DispatcherUnhandledException"
  • 在 App.xaml.cs 文件中:
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    MessageBox.Show("Error" + Environment.NewLine + e.Exception.Message, "Error");
    e.Handled = true;
}
  • 在 MainWindow.xaml.cs 文件中:
public MainWindow()
{
    InitializeComponent();
    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    Debug.Print(e.ToString());
}
  • 预览水晶报表的代码:
_report = new ReportDocument();
_report.Load("CrystalReport.rpt 的路径");
_report.SetDataSource(dataTable);

ViewerCore view = crystalReportViewer1.ViewerCore;
view.ReportSource = _report;
  • 预览报表的屏幕截图:
    预览报表截图

  • 更多信息:

    • 安装了 SAP Crystal Reports,适用于 Microsoft Visual Studio 版本 V13.0.32.4286。
    • 安装了适用于 .NET Framework 的 SAP Crystal Reports 运行时引擎(32 位)版本 V13.0.32.4286。
    • 安装了适用于 .NET Framework 的 SAP Crystal Reports 运行时引擎(64 位)版本 V13.0.32.4286。
    • 图片信息:JPEG 文件,50.4 KB,710 x 400 像素。
  • 提前感谢。

  • 如果选择类型为 "Microsoft Excel (XLSX) (*.xlsx)" 且在报表中不包含图片,可以成功导出。

  • 如果选择类型为 "Microsoft Excel - Data Only (XLSX) (*.xlsx)" 且在报表中包含图片,也可以成功导出。

  • 如果选择类型为 "Microsoft Excel (XLS) (*.xls)" 且在报表中包含图片,也可以成功导出。

  • 如果选择类型为 "Microsoft Excel (XLSX) (*.xlsx)" 且在报表中包含图片,则无法成功导出。

英文:

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;

Preview report screenshort

More information:

  • Installed SAP Crystal Reports, version for Microsoft Visual Studio V13.0.32.4286.
  • Installed SAP Crystal Reports runtime engine for .NET framework (32 bit) V13.0.32.4286.
  • Installed SAP Crystal Reports runtime engine for .NET framework (64 bit) V13.0.32.4286.
  • Picture info: JPEG file, 50.4 KB, 710 x 400 px.

Thanks in advance.

  • I can export successfully if select type "Microsoft Excel (XLSX) (*.xlsx)" without the picture in the report.
  • I can export successfully if select type "Microsoft Excel - Data Only (XLSX) (*.xlsx)" with the picture in the report.
  • I can export successfully if select type "Microsoft Excel (XLS) (*.xls)" with the picture in the report.
  • I cannot export file if select type "Microsoft Excel (XLSX) (*.xlsx)" with the picture

答案1

得分: 0

这是水晶报表的一个限制,您只能将数据导出到Excel,而不是图片,因为图片不属于数据,这将导致不可预测的结果。

选项包括:

  • 选择支持图片的导出格式之一,如PDF

  • 删除图片

  • 使用不同的报表提供程序

由于水晶报表在Visual Studio的最新版本中不再受支持,您可能需要考虑一种更长期的支持的不同报表方法。

请参考:

https://help.sap.com/docs/SAP_CRYSTAL_REPORTS,_DEVELOPER_VERSION_FOR_MICROSOFT_VISUAL_STUDIO/0d6684e153174710b8b2eb114bb7f843/45b016cb6e041014910aba7db0e91070.html?locale=en-US

如果您的用户特别喜欢在报告中查看其数据,您可以考虑基于Excel的报告和XSLT。我曾经在2009年的一家公司使用过这种方法,用于生成带有计算的电子表格。比我想象的要容易(从格式化的XSLX电子表格开始)。用户部门非常满意,这是我后来成功使用过几次的方法。

英文:

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:

https://help.sap.com/docs/SAP_CRYSTAL_REPORTS,_DEVELOPER_VERSION_FOR_MICROSOFT_VISUAL_STUDIO/0d6684e153174710b8b2eb114bb7f843/45b016cb6e041014910aba7db0e91070.html?locale=en-US

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

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.

答案2

得分: 0

不需要使用不同的报告提供者。在这里列出的第三方Crystal Reports查看器中,至少有一个支持将报告导出为.xlsx格式,而不是仅作为数据导出

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

英文:

No need to use a different reporting provider.
At least one of the 3rd-party Crystal Reports Viewers listed here supports exporting reports to .xlsx as a regular export rather than as a Data Only export.

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

WPF cannot use (built-in) export button to save .xlsx file with picture in CrystalReportsViewer

huangapple
  • 本文由 发表于 2023年2月16日 19:35:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471684.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定