ASP.NET 使用myxls导出excel
2013-09-29 10:44
477 查看
using org.in2bits.MyXls;
string sTitleName = "工作成绩报表"; Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(sTitleName + ".xls"));//添加头信息。为“文件下载/另存为”指定默认文件名称,对中文文件名进行URL编码解决中文乱码 //Response.AddHeader("Content-Length", "机车油耗效率统计.xls");//添加头文件,指定文件的大小,让浏览器显示文件下载的速度
org.in2bits.MyXls.XlsDocument xls = new XlsDocument(); xls.FileName = sTitleName + ".xls"; Worksheet sheet = xls.Workbook.Worksheets.Add("Sheet1"); XF xfBT = xls.NewXF(); xfBT.HorizontalAlignment = HorizontalAlignments.Centered; xfBT.VerticalAlignment = VerticalAlignments.Centered; xfBT.Pattern = 1; xfBT.PatternColor = Colors.Default30;//自己对Colors.Default30进行了修改,改为:无填充色 xfBT.Font.FontName = "宋体"; xfBT.Font.Height = 12 * 20; xfBT.Font.Bold = true; XF xf = xls.NewXF(); xf.HorizontalAlignment = HorizontalAlignments.Centered; xf.VerticalAlignment = VerticalAlignments.Centered; xf.Pattern = 1; xf.PatternColor = Colors.Default30; //xf.UseBorder = true; xf.TopLineStyle = 1; xf.TopLineColor = Colors.Black; xf.BottomLineStyle = 1; xf.BottomLineColor = Colors.Black; xf.LeftLineStyle = 1; xf.LeftLineColor = Colors.Black; xf.RightLineStyle = 1; xf.RightLineColor = Colors.Black; xf.Font.FontName = "宋体"; xf.Font.Height = 12 * 20; //xf.Font.ColorIndex = 1; //xf.Font.Bold = true; Cells cells = sheet.Cells; #region 列头 cells.Merge(1, 1, 1, 14); for (int i = 1; i < 14; i++) { cells.Add(1, i, sTitleName, xfBT); } sheet.Rows[1].RowHeight = 30 * 20; cells.Merge(2, 4, 1, 1); for (int i = 2; i <= 4; i++) { cells.Add(i, 1, "机车号", xf); } ColumnInfo colInfo = new ColumnInfo(xls, sheet); colInfo.ColumnIndexStart = 0; colInfo.ColumnIndexEnd = 0; colInfo.Width = (ushort)(4 * 2 * 256); sheet.AddColumnInfo(colInfo); cells.Merge(2, 4, 2, 2); for (int i = 2; i <= 4; i++) { cells.Add(i, 2, "班次", xf); } colInfo = new ColumnInfo(xls, sheet); colInfo.ColumnIndexStart = 1; colInfo.ColumnIndexEnd = 1; colInfo.Width = (ushort)(4 * 2 * 256); sheet.AddColumnInfo(colInfo); cells.Merge(2, 4, 3, 3); for (int i = 2; i <= 4; i++) { cells.Add(i, 3, "司机", xf); } colInfo = new ColumnInfo(xls, sheet); colInfo.ColumnIndexStart = 2; colInfo.ColumnIndexEnd = 2; colInfo.Width = (ushort)(4 * 2 * 256); sheet.AddColumnInfo(colInfo); #endregion for (int i = 1; i < 15; i++) { cells.Add(5, i, i, xf); } int nStartRow = 6; for (int i = 1; i <= dt.Rows.Count; ++i) { for (int j = 1; j <= dt.Columns.Count; ++j) { Cell cell = cells.Add(i + nStartRow - 1, j, dt.Rows[i - 1][j - 1].ToString(), xf); } } xls.Send(); Response.Flush(); Response.End();
相关文章推荐
- 使用ASP.NET的GridView导出/儲存資料至Excel,Word,Txt檔,Powerpoint
- ASP.NET使用NPOI类库导出Excel
- ASP.NET - 读写Excel - MyXls - 三方控件使用说明
- c# asp.net NPOI 使用本地模板导出excel
- asp.net 使用NPOI实现导出Excel功能
- asp.net使用npoi读取excel模板并导出下载详解
- 使用ASP.NET的GridView导出/儲存資料至Excel,Word,Txt檔,Powerpoint
- 使用ASP.NET的GridView导出/儲存資料至Excel,Word,Txt檔,Powerpoint
- 在ASP.NET Web Forms中使用页面导出伪xls Excel表格
- ASP.NET- 使用NPOI导入导出标准Excel
- ASP.Net使用NPOI导出Excel
- ASP.NET 导出Excel快捷的方法(不使用组件)
- ASP.NET 中 NPOI & LinqToSql 使用模板 导出 Excel
- ASP.NET导出Excel时长数字自动使用科学计数法的解决方法
- asp.net怎样使用NPOI 导出到excel和从excel导入到数据库
- ASP.NET使用NPOI类库导出Excel
- ASP.NET使用GridView导出Excel实现方法
- asp.net 导出Excel方法测试使用
- ASP.NET使用NPOI类库导出Excel(收藏)
- Asp.Net MVC 使用FileResult导出Excel数据文件