nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.65k stars 1.42k forks source link

fixed SXSSFWorkbook can not clear temp files when it called Dispose() on the IWorkbook interface. #1385

Open houlongchao opened 1 month ago

houlongchao commented 1 month ago

The floowing code generates 2 temp files and is not automatically cleaned. This change fixes the problem.

IWorkbook workbook = new SXSSFWorkbook();
var sheet = workbook.CreateSheet();
var row = sheet.CreateRow(0);
row.CreateCell(0).SetCellValue("test");

var sheet2 = workbook.CreateSheet();
var row2 = sheet2.CreateRow(0);
row2.CreateCell(0).SetCellValue("test");

workbook.Dispose();
tonyqus commented 1 month ago

You should apply using on SXSSFWorkbook. Then dispose will call Close method. It makes sense.

using(IWorkbook workbook = new SXSSFWorkbook())
{
 ...
}
houlongchao commented 1 month ago

I Know, but the close method only close the file, cleaning temp file only seen in the dispose method. You can test it, the temp file cannot currently be cleaned using the IWorkbook dispose.