除非手动保存,否则ACE.OLEDB无法打开SSRS呈现的XLSX

问题描述

我们有.NET呈现的SSRS报告。他们自己进行渲染和打开。但是,当我们尝试使用ACE 12再次打开它们时,它们在打开连接时失败。经过几次阅读后,我设法观察到,如果我们手动打开并保存xlsx文件,它将再次与ACE一起使用。

因此,这意味着通过我们的.NET解决方案呈现的SSRS返回的xlsx格式不正确。这是我们正在使用的代码,我想知道问题是否与SSRS相关,或者我们是否可以对此做点什么。也许下面的代码无法正确渲染xlsx。

xls正常工作。

OLEDB conn字符串:Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0};扩展属性='Excel 12.0; HDR = {1};

private static ReportOutput GetReportOutput(ReportConfig reportConfig)
{
    ReportViewer rptViewer = new ReportViewer();
    string urlreportserver = ConfigurationManager.AppSettings.Get(ConfigurationKeyConstants.SSRSUrl);

    rptViewer.ProcessingMode = ProcessingMode.Remote;
    rptViewer.ServerReport.reportserverUrl = new Uri(urlreportserver);
    rptViewer.ServerReport.ReportPath = string.Format("/SCS/{0}",reportConfig.reportName);
    rptViewer.ServerReport.SetParameters(reportConfig.reportParameters);

    ReportOutput reportOutput = new ReportOutput
    {
        result = rptViewer.ServerReport.Render(reportConfig.outputFormat,null,out string mimeType,out string encoding,out string fileNameExtension,out string[] streams,out Warning[] warnings),mimeType = mimeType,encoding = encoding,fileNameExtension = fileNameExtension,streams = streams,warnings = warnings
    };

    return reportOutput;
}

//-------------------------------------------
//data = reportOutput.result (in between)
//-------------------------------------------

private static void DownloadReport(byte[] data,string contentType,string filename,HttpResponse response)
{
    Stream stream = new MemoryStream(data);
    byte[] buffer = new Byte[Convert.ToInt32(stream.Length)];
    int length;

    try
    {
        response.ContentType = contentType;
        response.addheader("Content-disposition",String.Format("attachment; filename={0}",filename));

        if (response.IsClientConnected)
        {
            length = stream.Read(buffer,Convert.ToInt32(stream.Length));
            response.OutputStream.Write(buffer,length);
            response.Flush();
        }
    }
    finally
    {
        if (stream != null)
        {
            stream.Close();
        }

        response.Close();
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)