Asp.net高效导出excel篇之Aspose导出excel

上周在博客中写了一篇《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);

 

 

 

转载于:https://www.cnblogs.com/jianting1314/p/3680855.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值