Godaddy上ASP.net匯出excel的方法

來源:互聯網
上載者:User

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的方式提供下載的,有知道如何自動彈出下載提示對話方塊的麻煩告知一聲,謝謝。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.