国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
EPPlus與Excel完美的結合

筆者近期在公司項目中需要生產比較復雜的Excel報表, 問題點是單個Excel文件中必須能包含多個sheet, 按照以前項目的經驗, 此情況需要使用MS Office組件實現。但是客觀情況是office組件其版本兼容問題比較多(Excel版本不一致導致無法使用、excel進程無法回收、導致w3wp進程崩潰等), 無法把控摒棄之。

在codeplex上看到EPPlus組件, 好像可以解決上述問題。

EPPlus使用的是Open Office XML Format, 其讀寫支持Excel 2003/2007。

項目地址:http://epplus.codeplex.com/

在asp.net頁面上導出Excel代碼如下:

public static void DumpExcel(HttpContext context,string flieName,IDictionary<string,DataTable> dict)        {            using (ExcelPackage pck = new ExcelPackage())            {                foreach (var kp in dict)                {                    //Create the worksheet                    ExcelWorksheet ws = pck.Workbook.Worksheets.Add(kp.Key);                    //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1                    ws.Cells["A1"].LoadFromDataTable(kp.Value, true);                    ////Format the header for column 1-3                    //using (ExcelRange rng = ws.Cells["A1:C1"])                    //{                    //    rng.Style.Font.Bold = true;                    //    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid                    //    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue                    //    rng.Style.Font.Color.SetColor(Color.White);                    //}                    ////Example how to Format Column 1 as numeric                     //using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])                    //{                    //    col.Style.Numberformat.Format = "#,##0.00";                    //    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;                    //}                }                //Write it back to the client                var data = pck.GetAsByteArray();                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";                context.Response.AddHeader("content-disposition", "attachment;  filename=" + flieName + ".xlsx");                context.Response.AddHeader("Content-Length", data.Length.ToString());                context.Response.BinaryWrite(data);            }        }

參數dict傳遞的是sheetname和DataTable的鍵值對!

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Advanced Excels With EPPlus
Excel VBA語句集
c#中Excel數據的導入、導出
自學資料(Excel VBA)[收集整理3]
Excel的Range對象(C#)
Excel VBA 電子發(fā)票管理助手/重磅更新/電子發(fā)票登記管理系統(tǒng)(EXCEL版)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服