我不確定如何在我的asp.net mvc應用程序中將我的ActiveReports報表文檔導出到XLS。如何在ASP.Net MVC應用程序中將ActiveReport導出到XLS?
我到目前爲止的概念是有一個下拉導出類型和一個提交按鈕,將該值提交給我的控制器。當我在控制器上時,我重新生成報告並將其傳遞給我的Export方法。我不確定該導出方法返回的是什麼。我也在實際的xlsExport.Export方法中出現了超出範圍的錯誤。以下是我的導出方法。還要注意,reportBase.Report是一個ActiveReport3對象。
private ActionResult Export(ReportBase reportBase)
{
Response.ClearContent();
Response.ClearHeaders();
var exportType = Request.Form["exportType"];
switch (exportType)
{
case "RTF":
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=report.rtf");
var rtfExport = new RtfExport();
rtfExport.Export(reportBase.Report.Document, Response.OutputStream);
break;
case "TIFF":
Response.ContentType = "image/tiff";
Response.AddHeader("Content-Disposition", "attachment;filename=report.tif");
var tiffExport = new TiffExport();
var filePath = System.IO.Path.GetTempFileName();
tiffExport.Export(reportBase.Report.Document, filePath);
var fileStream = System.IO.File.Open(filePath, System.IO.FileMode.Open);
var bufferLength = (int)fileStream.Length;
var output = new byte[bufferLength];
var bytesRead = fileStream.Read(output, 0, bufferLength);
Response.OutputStream.Write(output, 0, bytesRead);
System.IO.File.Delete(filePath);
break;
case "XLS":
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=report.xls");
var xlsExport = new XlsExport();
xlsExport.Export(reportBase.Report.Document, Response.OutputStream);
break;
}
Response.Flush();
Response.End();
return View("Display", reportBase);
}
謝謝Talljoe!這不僅使我的代碼看起來更好,它解決了問題。我不確定如何操縱MVC方式的響應。謝謝您的幫助! – 2009-06-04 13:20:01