foreach (DataColumn column in SourceTable.Columns){ dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString()); if (row[column].ToString().Contains("\n")) { //將目前欄位的CellStyle設定為自動換行 HSSFCellStyle cs = workbook.CreateCellStyle(); cs.WrapText = true; dataRow.GetCell(column.Ordinal).CellStyle = cs; //因為換行所以愈設幫他Row的高度變成兩倍 dataRow.HeightInPoints = 2 * sheet.DefaultRowHeight / 20; }}