npoi导出模板文件

    /// 
    /// 导出地址以及导出文件名称
    /// 
    /// 
    /// 
    public string OutModel(List 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;
    }

你可能感兴趣的:(关于程序)