Aspose.Cells组件导出excel文件
程序员文章站
2022-04-10 09:56:04
本文实例为大家分享了aspose.cells导出excel文件的方法,供大家参考,具体内容如下
///
/// 导出...
本文实例为大家分享了aspose.cells导出excel文件的方法,供大家参考,具体内容如下
/// <summary> /// 导出数据到本地 /// </summary> /// <param name="dt">要导出的数据</param> /// <param name="tablename">导出名称</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;//单元格 //为标题设置样式 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;//单元格内容自动换行 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;//表格列数 int rownum = dt.rows.count;//表格行数 //生成行1 标题行 cells.merge(0, 0, 1, colnum);//合并单元格 cells[0, 0].putvalue(tablename);//填写内容 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); } //生成数据行 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)); }
调用
string tabletitle = "账号,密码"; excelhelp.outfiletodisk(dt, "账户信息", tabletitle , httpcontext.current.response);
前台页面
window.open("方法", "_blank");//点击下载
aspose.cells.dll 下载地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
Excel-Boot(一款Excel导入导出解决方案组成的轻量级开源组件)
-
【C#常用方法】2.DataTable(或DataSet)与Excel文件之间的导出与导入(使用NPOI)
-
java数据导出成Excel文件
-
Yii框架使用PHPExcel导出Excel文件的方法分析【改进版】
-
PHP导出MySQL数据到Excel文件(fputcsv)
-
HTML导出Excel文件(兼容IE及所有浏览器)
-
php导出中文内容excel文件类实例
-
javascript导出csv文件(excel)的方法示例
-
Laravel Excel 实现 Excel-CSV 文件导入导出功能
-
java实现导出文字+数据的excel文件并返回文件流