// HSSFWorkbook XSSFWorkbook
IWorkbook books = new HSSFWorkbook();//生成xlsx格式excel
#region xlsx的非虚线
// ICellStyle headStyle = books.CreateCellStyle();
// headStyle.BorderTop = BorderStyle.Thin;
// headStyle.BorderRight = BorderStyle.Thin;
// headStyle.BorderBottom = BorderStyle.Thin;
// headStyle.BorderLeft = BorderStyle.Thin;
#endregion
ISheet Sheet1 = books.CreateSheet("Sheet1");
IRow Sheet1row1 = Sheet1.CreateRow(0);
ISheet Sheet2 = books.CreateSheet("Sheet2");
#region 声明
IRow notesInfo = Sheet2.CreateRow(1);
notesInfo.Height = 10 * 200;//设置高度
ICell notesTitle = notesInfo.CreateCell(0);
ICellStyle notesStyle = books.CreateCellStyle();
notesStyle.WrapText = true;//设置换行这个要先设置
StringBuilder noteString = new StringBuilder("注意事项: \n");
noteString.Append("1、模板中标识为*号的栏目为必填项,导入时不能为空!\n");
noteString.Append("2.2、部分栏目内容需从如下表格中选择,否则系统禁止导入!\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.会员等级:" + "" + ";\n");
notesStyle.WrapText = true;
notesTitle.SetCellValue(noteString.ToString());
notesTitle.CellStyle = notesStyle;//设置换行
//CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 1, 0, 2);
//Sheet2.AddMergedRegion(cellRangeAddress);
//Sheet2.SetColumnWidth(0,40);
//IRow Sheet2RowObj = Sheet2.CreateRow(0);
//Sheet2RowObj.CreateCell(0).SetCellValue("序号");
MemoryStream m = new MemoryStream();
MemoryStream stream = new MemoryStream();
books.Write(m);
var byteArray = m.ToArray();
books.Write(stream);
return File(byteArray, "application/vnd.ms-excel", @"税务" + DownLoadTime + DownLoadType + ".xls");//通过字节流进行输出