Excel 除非手动保存,否则ACE.OLEDB无法打开SSRS呈现的XLSX
我们有.NET提供的SSRS报告。他们正在自己渲染和打开。但当我们试图使用ACE 12再次打开它们时,它们在打开连接时失败。读了几遍之后,我发现如果我们手动打开并保存xlsx文件,它会再次与ACE一起工作 因此,这意味着通过.NET解决方案呈现SSR会返回未正确格式化的xlsx。这就是我们正在使用的代码,我想知道这个问题是否与SSRS有关,或者我们是否可以对此采取一些措施。可能下面的代码没有正确呈现xlsx xls工作正常 OLEDB连接字符串:Excel 除非手动保存,否则ACE.OLEDB无法打开SSRS呈现的XLSX,excel,reporting-services,oledb,xlsx,Excel,Reporting Services,Oledb,Xlsx,我们有.NET提供的SSRS报告。他们正在自己渲染和打开。但当我们试图使用ACE 12再次打开它们时,它们在打开连接时失败。读了几遍之后,我发现如果我们手动打开并保存xlsx文件,它会再次与ACE一起工作 因此,这意味着通过.NET解决方案呈现SSR会返回未正确格式化的xlsx。这就是我们正在使用的代码,我想知道这个问题是否与SSRS有关,或者我们是否可以对此采取一些措施。可能下面的代码没有正确呈现xlsx xls工作正常 OLEDB连接字符串:Provider=Microsoft.ACE.OL
Provider=Microsoft.ACE.OLEDB.12.0;数据源={0};EXCEL2.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, 0, Convert.ToInt32(stream.Length));
response.OutputStream.Write(buffer, 0, length);
response.Flush();
}
}
finally
{
if (stream != null)
{
stream.Close();
}
response.Close();
}
}