zoukankan      html  css  js  c++  java
  • Excel导出采用mvc的ExcelResult继承遇到的问题Npoi导出

     #region 构建Excel文档
                //创建Excel文件的对象
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                NPOI.SS.UserModel.CellStyle style = book.CreateCellStyle();
                style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
                ////设置边框格式
                style.BorderTop = NPOI.SS.UserModel.CellBorderType.THIN;
                style.BorderLeft = NPOI.SS.UserModel.CellBorderType.THIN;
                style.BorderRight = NPOI.SS.UserModel.CellBorderType.THIN;
                style.BorderBottom = NPOI.SS.UserModel.CellBorderType.THIN;
    
                //添加一个sheet
                NPOI.SS.UserModel.Sheet sheet1 = book.CreateSheet("Sheet1");
                //获取list数据
                NPOI.SS.UserModel.Row row1 = sheet1.CreateRow(0);
                SetColcumns(book, sheet1, style, 0, row1, "编号");
                SetColcumns(book, sheet1, style, 1, row1, "");
                SetColcumns(book, sheet1, style, 2, row1, "是否本人");
                for (int i = 0; i < 34; i++)
                {
                    sheet1.SetColumnWidth(i, 20 * 256);
                }
                //将数据逐步写入sheet1各个行
                int num = 0;
                foreach (var item in cooperates)
                {
                    NPOI.SS.UserModel.Row rowtemp = sheet1.CreateRow(num + 1);
    
                    SetColcumns(book, sheet1, style, 0, rowtemp, item.ID.ToString());
                    SetColcumns(book, sheet1, style, 1, rowtemp, item.UserName);
                    SetColcumns(book, sheet1, style, 2, rowtemp, item.IsSelfStrc);
                    num++;
                }
                byte[] data = null;
                using (MemoryStream ms = new MemoryStream())
                {
                    book.Write(ms);
                    ms.Flush();
                    ms.Position = 0;
                    data = ms.GetBuffer();
                }
                return File(data, "application/vnd.ms-excel", "信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                #endregion
  • 相关阅读:
    git command
    互联网应用架构概览-学习笔记
    机器学习基础概念-阿里大学课程学习笔记
    Python的并行求和例子
    C语言处理CSV数据
    Pattern Evaluation
    Python写的大小写转换小工具
    处理输入为非对角阵的Clustering by fast search and find of density peak代码
    css点击下层穿透上层元素
    浏览器全屏效果
  • 原文地址:https://www.cnblogs.com/daizhipeng/p/10701832.html
Copyright © 2011-2022 走看看