NPOI操作Excel 让单元格的内容换行

      // HSSFWorkbook XSSFWorkbook
            IWorkbook books = new HSSFWorkbook();//生成xlsx格式excel
            #region xlsx的非虚线

            //  ICellStyle headStyle = books.CreateCellStyle();
            // headStyle.BorderTop = BorderStyle.Thin;
            // headStyle.BorderRight = BorderStyle.Thin;
            // headStyle.BorderBottom = BorderStyle.Thin;
            //  headStyle.BorderLeft = BorderStyle.Thin;

            #endregion
            ISheet Sheet1 = books.CreateSheet("Sheet1");
            IRow Sheet1row1 = Sheet1.CreateRow(0);
            ISheet Sheet2 = books.CreateSheet("Sheet2");
            #region 声明
            IRow notesInfo = Sheet2.CreateRow(1);
            notesInfo.Height = 10 * 200;//设置高度
            
            ICell notesTitle = notesInfo.CreateCell(0);
            ICellStyle notesStyle = books.CreateCellStyle();
            notesStyle.WrapText = true;//设置换行这个要先设置
            StringBuilder noteString = new StringBuilder("注意事项: \n");
            noteString.Append("1、模板中标识为*号的栏目为必填项,导入时不能为空!\n");
            noteString.Append("2.2、部分栏目内容需从如下表格中选择,否则系统禁止导入!\n");
            //noteString.Append("3.性别:填写“男”或者“女”;\n");
            //noteString.Append("4.手机号码:只能是11位数字的标准手机号码;\n");
            //noteString.Append("5.固定电话:最好填写为“区号+电话号码”,例:075529755361;\n");
            //noteString.Append("6.会员生日:填写格式“年-月-日”,例:1990-12-27,没有则不填;\n");
            //noteString.Append("7.会员等级:" + "" + ";\n");
            notesStyle.WrapText = true;
            notesTitle.SetCellValue(noteString.ToString());
            notesTitle.CellStyle = notesStyle;//设置换行

            //CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 1, 0, 2);
            //Sheet2.AddMergedRegion(cellRangeAddress);
            //Sheet2.SetColumnWidth(0,40);
            //IRow Sheet2RowObj = Sheet2.CreateRow(0);
            //Sheet2RowObj.CreateCell(0).SetCellValue("序号");
   MemoryStream m = new MemoryStream();
            MemoryStream stream = new MemoryStream();
            books.Write(m);
            var byteArray = m.ToArray();
            books.Write(stream);
            return File(byteArray, "application/vnd.ms-excel", @"税务" + DownLoadTime + DownLoadType + ".xls");//通过字节流进行输出

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值