是否可以使用 ServerReport.Render 或 ServerReport.RenderStream 将报告导出到 SSRS 2008 R2 上的 CSV 可编程性?
这很奇怪,因为我们可以使用 Report Viewer 来做到这一点,但是当使用渲染在代码中将格式更改为 CSV 时,我会遇到一些异常。
这是我正在使用的代码,可以完美地以 XLS、DOC 和 PDF 格式导出报告:
private void ExportReport(String format)
{
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
string fileName = _reportName.Replace("Rep", "Report") + "_" + DateTime.Now.ToString("yyyyMMdd HH:mm");
PrepareReportParameters();
rv.ServerReport.SetParameters(lstReportParameters);
byte[] bytes = rv.ServerReport.Render(format, null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
更新 1
这是我在上述方法中选择“CSV”作为“字符串格式”时遇到的异常:
You have attempted to use a rendering extension that is either not registered for this report server or it is not supported in this edition of Reporting Services. (rsRenderingExtensionNotFound)
谢谢