Aspose.Cells組件導(dǎo)出excel文件
更新時(shí)間:2018年12月13日 15:59:23 作者:世界太過浮夸
這篇文章主要介紹了利用Aspose.Cells組件導(dǎo)出excel文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Aspose.Cells導(dǎo)出excel文件的方法,供大家參考,具體內(nèi)容如下
/// <summary> /// 導(dǎo)出數(shù)據(jù)到本地 /// </summary> /// <param name="dt">要導(dǎo)出的數(shù)據(jù)</param> /// <param name="tableName">導(dǎo)出名稱</param> /// <param name="tableTitle">表格行名格式“賬號,密碼”</param> /// <param name="response">請求</param> public static void OutFileToDisk(DataTable dt, string tableName, string tableTitle, HttpResponse response) { Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[0]; //工作表 Cells cells = sheet.Cells;//單元格 //為標(biāo)題設(shè)置樣式 Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增樣式 styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中 styleTitle.Font.Name = "宋體";//文字字體 styleTitle.Font.Size = 18;//文字大小 styleTitle.Font.IsBold = true;//粗體 //樣式2 Style style2 = workbook.Styles[workbook.Styles.Add()];//新增樣式 style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中 style2.Font.Name = "宋體";//文字字體 style2.Font.Size = 14;//文字大小 style2.Font.IsBold = true;//粗體 style2.IsTextWrapped = true;//單元格內(nèi)容自動換行 style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //樣式3 Style style3 = workbook.Styles[workbook.Styles.Add()];//新增樣式 style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中 style3.Font.Name = "宋體";//文字字體 style3.Font.Size = 12;//文字大小 style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; int Colnum = dt.Columns.Count;//表格列數(shù) int Rownum = dt.Rows.Count;//表格行數(shù) //生成行1 標(biāo)題行 cells.Merge(0, 0, 1, Colnum);//合并單元格 cells[0, 0].PutValue(tableName);//填寫內(nèi)容 cells[0, 0].SetStyle(styleTitle); cells.SetRowHeight(0, 38); //生成行2 列名行 string[] Tile = tableTitle.Split(','); for (int i = 0; i < Colnum; i++) { cells[1, i].PutValue(Tile[i]); cells[1, i].SetStyle(style2); cells.SetRowHeight(1, 25); } //生成數(shù)據(jù)行 for (int i = 0; i < Rownum; i++) { for (int k = 0; k < Colnum; k++) { cells[2 + i, k].PutValue(dt.Rows[i][k].ToString()); cells[2 + i, k].SetStyle(style3); } cells.SetRowHeight(2 + i, 24); } workbook.Save(response, HttpUtility.UrlEncode(tableName, System.Text.Encoding.UTF8) + ".xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003)); }
調(diào)用
string tableTitle = "賬號,密碼"; ExcelHelp.OutFileToDisk(dt, "賬戶信息", tableTitle , HttpContext.Current.Response);
前臺頁面
window.open("方法", "_blank");//點(diǎn)擊下載
Aspose.Cells.dll 下載地址
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
.NET Core跨平臺執(zhí)行命令、腳本的方法詳細(xì)
這篇文章主要給大家介紹了關(guān)于.NET Core跨平臺執(zhí)行命令、腳本的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05ASP.NET在IIS上注冊報(bào)0x800702e4錯(cuò)誤解決方法
報(bào)一個(gè)0x800702e4 請求的操作需要提升的錯(cuò)誤。解決的方法和前面大同小異,給這個(gè)aspnet_regiis.exe創(chuàng)建一個(gè)快捷方式,給它的目標(biāo)后面加上 一個(gè)-i,再右擊這個(gè)快捷方式,以管理員身份運(yùn)行,就行了2012-08-08.Net微信開發(fā)之如何解決access_token過期問題
這篇文章主要為大家詳細(xì)介紹了.Net微信開發(fā)之如何解決access_token過期問題的方法,感興趣的小伙伴們可以參考一下2016-06-06ASP.NET中Application全局對象用法實(shí)例淺析
這篇文章主要介紹了ASP.NET中Application全局對象用法,較為詳細(xì)的分析了ASP.NET中Application全局對象的功能、定義及使用中的相關(guān)注意事項(xiàng),需要的朋友可以參考下2015-06-06利用ASP.NET MVC和Bootstrap快速搭建個(gè)人博客之后臺dataTable數(shù)據(jù)列表
jQuery dataTables 插件是一個(gè)優(yōu)秀的表格插件,應(yīng)用非常廣泛,本文給大家介紹利用ASP.NET MVC和Bootstrap快速搭建個(gè)人博客之后臺dataTable數(shù)據(jù)列表,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-07-07