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

HSSFWorkbook workbook = new HSSFWorkbook();
// 工作簿 
ISheet sheet = workbook.CreateSheet("会员列表");
IRow notesInfo = sheet.CreateRow(1);
                notesInfo.Height = 15 * 200;//设置高度
                ICell notesTitle = notesInfo.CreateCell(0);
                ICellStyle notesStyle = workbook.CreateCellStyle();
                notesStyle.WrapText = true;//设置换行这个要先设置
                StringBuilder noteString = new StringBuilder("相关数据字典:(★★请严格按照相关格式填写,以免导入错误★★)\n");
                noteString.Append("1.列名带有' * '是必填列;\n");
                noteString.Append("2.会员卡号:会员卡号长度为3~20位,且只能数字或者英文字母;\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.会员等级:" + gradeResult + ";\n");
                notesStyle.WrapText = true;
                notesTitle.SetCellValue(noteString.ToString());
                notesTitle.CellStyle= notesStyle;//设置换行

上面的代码是放在这个例子里面的:C#生成Excel保存到服务器端并下载

这个是下载下来的Excel最终的效果图如下:

 

已经自动换行

posted @ 2017-05-23 19:45  风琴~云淡  阅读(17455)  评论(1编辑  收藏  举报