EPPlus - Do I need to call Dispose on objects like ExcelRange?

你离开我真会死。 提交于 2019-12-07 06:36:36

问题


I'm using the C# EPPlus library to create Excel documents.

ExcelWorksheet ws = pkg.Workbook.Worksheets.Add("Sheet1");

ws.Cells["E3"].Value = "Foo";
ws.Cells["F3"].Value = "Bar";
ws.Cells["F3"].Style.Font.Bold = true;

The ws.Cells[] return type is ExcelRange which has a Dispose() method. Do I need to call it each time I use ws.Cells[] ?

Something like

ExcelWorksheet ws = pkg.Workbook.Worksheets.Add("Sheet1");
ExcelRange rng;

rng = ws.Cells["E3"];
rng.Value = "Foo";
rng.Dispose();

using (rng = ws.Cells["F3"])
{
    rng.Value = "Bar";
    rng.Style.Font.Bold = true;
}

would be a heavy syntax !

Is it really necessary ?


回答1:


The answer is no.

Why?

I took a look in the source code from EPPlus and this is the content of the Dispose method of the ExcelRangeBase:

public void Dispose()
{
    //_worksheet = null;
}

I don't think this is going to help you in any way...



来源:https://stackoverflow.com/questions/23132659/epplus-do-i-need-to-call-dispose-on-objects-like-excelrange

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!