/// <summary>
/// 导出地址以及导出文件名称
/// </summary>
/// <param name="CollumList"></param>
/// <returns></returns>
public string OutModel(List<string> CollumList)
{
IWorkbook workbook;
string ModelFileName = DateTime.Now.ToString("yyyyMMddmm") + ".xlsx";
string path = Environment.CurrentDirectory + "\\" + ModelFileName;
workbook = new XSSFWorkbook();
//if (workbook == null) { return; }
ISheet sheet = workbook.CreateSheet("当前模板");
//表头
IRow row = sheet.CreateRow(0);
for (int i = 0; i < CollumList.Count; i++)
{
ICell cell = row.CreateCell(i);
cell.SetCellValue(CollumList[i].Name);
}//完成创建表头
MemoryStream stream = new MemoryStream();
workbook.Write(stream);
var buf = stream.ToArray();
//保存为Excel文件
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
fs.Write(buf, 0, buf.Length);
fs.Flush();
}
return path;
}
npoi导出模板文件
最新推荐文章于 2024-06-17 23:31:56 发布