using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExcelHelper
{
public class ExcelNpoiHelper:IDisposable
{
IWorkbook workbook;
ISheet sheet;
string srcPath = @"../Template/temple.xlsx";
string dstPath= @"../Output/";
List<CellStyle> cellStyles = new List<CellStyle>
{
new CellStyle("defaultFont","Calibri",11)
};
Dictionary<string, ICellStyle> cellStylesDictionary = new Dictionary<string, ICellStyle>();
public ExcelNpoiHelper(string fileName)
{
dstPath += fileName;
File.Copy(srcPath, dstPath, true);
WorkBookInit(dstPath);
}
public void WorkBookInit(string dstPath)
{
using (FileStream fs = new FileStream(dstPath, FileMode.Open, FileAccess.Read))
{
workbook = WorkbookFactory.Create(fs);
cellStyles.ForEach(x => WorkbookAddStyle(x));
sheet
c# 基于NPOI的Excel通用帮助类库
于 2023-05-22 11:04:13 首次发布