Copy sheet from one workbook to another using NPOI

2019-05-07 19:58发布

I need to copy a sheet from one workbook to another. I am trying with the below code, but it is not working:

ISheet newSheet = wb.GetSheetAt(0).CopySheet("WeeklyReport");
string filePath = "billing_template2.xlsx";
XSSFWorkbook billingWorkbook;
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
    billingWorkbook = new XSSFWorkbook(fs);
}

billingWorkbook.Add(newSheet);

where wb is the source workbook and billingWorkbook is my destination workbook.

Note: My destination workbook already had a sheet. I need to add the copied sheet after this one.

标签: c# npoi
0条回答
登录 后发表回答