Asp.net高效导出excel篇之Aspose导出excel
2014-04-22 16:49
381 查看
上周在博客中写了一篇《Asp.net高效导出Excel篇》在发布之后收到很多热心网友的建议——使用Excel第三方引擎如NOPI、Aspose.cell等导出Excel,优点:效率高、不需要在客户端安装Excel组件,功能强大,可制作高难度Excel形式报表。在众多优点的吸引下我选择了Aspose.cell做为研究对象,并最终实现我项目的需求,现将我做的一个试验例子列出来以供学习。
1、先在项目中引用Aspose.Cells.dll
2、using Aspose.Cells;
Aspose.Cells.Workbook wb=new Aspose.Cells.Workbook();//实例化Workbook对象
Aspose.Cells.Worksheet sheet = wb.Worksheets[0];
Aspose.Cells.Cells cells = sheet.Cells;
int styleIndex = wb.Styles.Add();//设置样式,如字体大小等
Aspose.Cells.Style style = wb.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Name = "仿宋";
Range range = sheet.Cells.CreateRange(0, 0, 1, 6); //获取excel第0行第0列,一行6列范围
range.Style = style;
range.Merge();//合并单元格
cells[0, 0].PutValue("xxxxxxxxxxxxxxxxxx");//给单元格赋值
//excel单元格注释
Comments comments = wb.Worksheets[0].Comments;
int commentIndex = comments.Add(0,0);
Comment comment = comments[commentIndex];
comment.Note = "ooooooo";
comment.Font.Name = "lalalala";
int row = 100;
int col = 3;
for (int i = 3; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cells[i, j].PutValue(i);
}
}
sheet.AutoFilter.Range = "A8:P"+index;//筛选
sheet.AutoFitColumns();
int styleIndex2 = wb.Styles.Add();
Aspose.Cells.Style style2 = wb.Styles[styleIndex2];
style2.IsTextWrapped = true;//设置单元格自动换行
Range range10= sheet.Cells.CreateRange(8, 1, dt.Rows.Count, 1);
range10.Style = style2;
range10.ColumnWidth = 30;
range10.RowHeight = 50;
wb.Save(ExcelFullName);
1、先在项目中引用Aspose.Cells.dll
2、using Aspose.Cells;
Aspose.Cells.Workbook wb=new Aspose.Cells.Workbook();//实例化Workbook对象
Aspose.Cells.Worksheet sheet = wb.Worksheets[0];
Aspose.Cells.Cells cells = sheet.Cells;
int styleIndex = wb.Styles.Add();//设置样式,如字体大小等
Aspose.Cells.Style style = wb.Styles[styleIndex];
style.Font.Size = 12;
style.Font.IsBold = true;
style.Font.Name = "仿宋";
Range range = sheet.Cells.CreateRange(0, 0, 1, 6); //获取excel第0行第0列,一行6列范围
range.Style = style;
range.Merge();//合并单元格
cells[0, 0].PutValue("xxxxxxxxxxxxxxxxxx");//给单元格赋值
//excel单元格注释
Comments comments = wb.Worksheets[0].Comments;
int commentIndex = comments.Add(0,0);
Comment comment = comments[commentIndex];
comment.Note = "ooooooo";
comment.Font.Name = "lalalala";
int row = 100;
int col = 3;
for (int i = 3; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cells[i, j].PutValue(i);
}
}
sheet.AutoFilter.Range = "A8:P"+index;//筛选
sheet.AutoFitColumns();
int styleIndex2 = wb.Styles.Add();
Aspose.Cells.Style style2 = wb.Styles[styleIndex2];
style2.IsTextWrapped = true;//设置单元格自动换行
Range range10= sheet.Cells.CreateRange(8, 1, dt.Rows.Count, 1);
range10.Style = style2;
range10.ColumnWidth = 30;
range10.RowHeight = 50;
wb.Save(ExcelFullName);
相关文章推荐
- asp.net mvc用aspose.cells 导出xlsx格式的excel。无残留
- ASP.NET 高效导出Excel
- Asp.net开发经验-利用Aspose.Words按模板导出Word(注:Excel可以使用Aspose.Excel)
- ASP.NET 2.0中将 GridView 导出到 Excel 文件中
- Asp.net中DataTable导出到Excel的方法介绍
- Asp.net 导出标准Excel
- Asp.Net 导出 Excel 数据的9种方案
- Asp.Net导出GridView数据到Excel
- asp.net导出Excel
- asp.net Grid 导出Excel实现程序代码
- asp.net中Excel导入导出控件 2.0升级版本和1.0版本代码开源
- asp.net导出数据到Excel的三种方法
- ASP.NET导出数据到excel中
- sql server 与 excel 互导以及在asp.net中从DataTable导出到excel
- asp.net导出Excel类库代码分享
- asp.net 导出Excel 设置格式
- 关于asp.net导出Excel时关联迅雷下载
- asp.net 导出excel 问题 (服务器的部署)
- ASP.NET对EXCEL的导入导出
- ASP.NET中导出excel/word等类型文件的简单方法