【发布时间】:2016-07-27 23:03:10
【问题描述】:
我正在使用 EPPlus 库创建一个 excel 文件,我想将其下载到客户端。
这里是一个 EPPlus 的例子
ExcelPackage pck = new ExcelPackage();
var ws = pck.Workbook.Worksheets.Add("Sample1");
ws.Cells["A1"].Value = "Sample 1";
ws.Cells["A1"].Style.Font.Bold = true;
var shape = ws.Drawings.AddShape("Shape1", eShapeStyle.Rect);
shape.SetPosition(50, 200);
shape.SetSize(200, 100);
shape.Text = "Sample 1 saves to the Response.OutputStream";
pck.SaveAs(HttpContext.Current.Response.OutputStream);
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Sample1.xlsx");
此代码创建 xls 文件并允许从 aspx 页面将其下载到客户端。 我试图从 my.aspx 页面请求带有“HttpWebRequest”类的 xls 文件,但我收到一条错误消息,提示“由于对象的当前状态,操作无效”。
如何将这个 xls 文件从服务器下载到客户端?
【问题讨论】:
标签: c# excel silverlight epplus