stupid liar,dom-047,天才风水师小玲
本文实例为大家分享了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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论