.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最終的效果圖如下:

 

已經自動換行


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM