Aspose.Cells组件导出excel文件
2018-12-13 20:03
966 查看
本文实例为大家分享了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 下载地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- (C#)利用Aspose.Cells组件导入导出excel文件
- (C#)利用Aspose.Cells组件导入导出excel文件
- 使用Aspose.Cells组件生成Excel文件实例
- 使用Aspose.Cells组件生成Excel文件实例
- 利用Aspose.Cells 组件导出数据到excel
- 使用JXL组件操作Excel和导出文件
- aspose.cells excel表格导入导出
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
- Excel组件Aspose.Cells 系列组件介绍 | 附下载
- extjs+Aspose.Cells导出到Excel
- c#使用aspose.cells 从datatable导出数据到excel
- Aspose.cells 导出Excel
- C#使用Aspose.Cells导出Excel简单实现
- DataTable 用Aspose.Cells导出Excel
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
- Aspose.Cells 根据Excel模板导出数据统计
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
- C# WinForm使用Aspose.Cells.dll 导出导入Excel/Doc 完整实例教程
- C#使用Aspose.Cells导出excel
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]