如何使报表查看器控件以xls格式而不是xlsx导出?

时间:2023-01-15 13:13:43

Our application needs to be able to generate .xls format from the report viewer control. However, when I try to export to Excel, it only gives me two options (.xlsx and Other files).

我们的应用程序需要能够从报表查看器控件生成.xls格式。但是,当我尝试导出到Excel时,它只给我两个选项(.xlsx和其他文件)。

In order to generate as .xls, we need to use 'Other files' option and set to .xls but this will result in mismatch of file format and extension and the user will always obtain a warning dialog box when trying to open that file. I suspect it was just renaming the file to .xls but its format is still .xlsx.

为了生成.xls,我们需要使用“其他文件”选项并设置为.xls,但这会导致文件格式和扩展名不匹配,并且用户在尝试打开该文件时将始终获得警告对话框。我怀疑它只是将文件重命名为.xls,但其格式仍为.xlsx。

Is it possible to set the default export format of Excel type files to .xls for the Report Viewer control?

是否可以为报表查看器控件将Excel类型文件的默认导出格式设置为.xls?

如何使报表查看器控件以xls格式而不是xlsx导出?

Figure 1: Report viewer shows 3 types of files to export in

图1:报告查看器显示要导出的3种类型的文件

如何使报表查看器控件以xls格式而不是xlsx导出?

Figure 2: Report viewer defaults to .xlsx format when choosing a file. Would prefer it to default to .xls format instead

图2:选择文件时,报告查看器默认为.xlsx格式。宁愿它默认为.xls格式

1 个解决方案

#1


0  

  1. Handle report export event
  2. 处理报告导出事件
  3. Use ReportViewer's ExportDialog() method and use ListRenderingExtensions() method to see the list of extensions available
  4. 使用ReportViewer的ExportDialog()方法并使用ListRenderingExtensions()方法查看可用的扩展列表
  5. Set e.Cancel = true to prevent a repeat of this event
  6. 设置e.Cancel = true以防止重复此事件

Code:

码:

    private void reportViewerControl_ReportExport(object sender, ReportExportEventArgs e)
    {
        if(e.Extension.LocalizedName.ToUpper().Equals("EXCEL"))
        {
            reportViewerControl.ExportDialog(reportViewerControl.LocalReport.ListRenderingExtensions()[0]);
            e.Cancel = true;
        }
    }

#1


0  

  1. Handle report export event
  2. 处理报告导出事件
  3. Use ReportViewer's ExportDialog() method and use ListRenderingExtensions() method to see the list of extensions available
  4. 使用ReportViewer的ExportDialog()方法并使用ListRenderingExtensions()方法查看可用的扩展列表
  5. Set e.Cancel = true to prevent a repeat of this event
  6. 设置e.Cancel = true以防止重复此事件

Code:

码:

    private void reportViewerControl_ReportExport(object sender, ReportExportEventArgs e)
    {
        if(e.Extension.LocalizedName.ToUpper().Equals("EXCEL"))
        {
            reportViewerControl.ExportDialog(reportViewerControl.LocalReport.ListRenderingExtensions()[0]);
            e.Cancel = true;
        }
    }