欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

操作 Excel 的 NPOI 网格,操作 Excel 单元格的自动换行符

最编程 2024-03-16 19:09:35
...
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;//设置换行