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最終的效果圖如下:
已經自動換行