我们正在使用Kendo Grid进行列表,并需要使用过滤器将记录导出到doc / Docx文件。
是否有人知道如何将IEumarable对象导出到Doc / Docx文件。
此处代码段:
public FileResult ExportToWord([DataSourceRequest]DataSourceRequest request)
{
IEnumerable rows = dtView.ToDataSourceResult(request).Data;
MemoryStream output = new MemoryStream();
workbook.Write(output);
return File(output.ToArray(), "application/vnd.ms-word", "GridExcelExport.doc");
}
任何帮助?
答案 0 :(得分:1)
您可以尝试以下代码
public ActionResult ExportData()
{
GridView gv = new GridView();
gv.DataSource = db.Studentrecord.ToList();
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=Marklist.doc");
Response.ContentType = "application/vnd.ms-word ";
Response.Charset = string.Empty;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
return RedirectToAction("StudentDetails");
}