Godaddy上ASP.net导出excel的方法

来源:互联网 发布:数据交换接口规范 编辑:程序博客网 时间:2024/06/07 03:08

Godddy上导入excel没有问题,不过在导出excel的时候提示System.Security.SecurityException。

解决方法步骤:

1. 到http://nopcommerce.codeplex.com/ 下载nopcommerce-a6bd30c10ba3.zip,这是我下载的版本。

2. 解压后到文件夹nopCommerce_a6bd30c10ba3\src\packages\EPPlus.2.9.0.1\lib\2.0中找到EPPlus.dll

3. 将EPPlus.dll放到自己工程的bin文件夹中,或者添加引用

4. 使用方法:

using System;using System.IO;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using Maticsoft.DBUtility;using OfficeOpenXml;protected void Export(){    FileInfo newFile = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "/Download/Download.xls");    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Download/Download.xls"))    {        File.Delete(AppDomain.CurrentDomain.BaseDirectory + "/Download/Download.xls");    }              using (ExcelPackage xlPackage = new ExcelPackage(newFile))    {        ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("SheetName");        worksheet.Cells[1, 1].Value = "a1";        worksheet.Cells[1, 2].Value = "b1";        worksheet.Cells[2, 1].Value = "a2";        worksheet.Cells[2, 2].Value = "b2";        xlPackage.Save();    }}

这里仅仅是保存文件到服务器,并没有自动下载,需要自动下载的需要自己处理一下,我使用url的方式提供下载的,有知道如何自动弹出下载提示对话框的麻烦告知一声,谢谢。

原创粉丝点击