Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

excel

epplus

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 ?

like image 506
Etienne Fesser Avatar asked Apr 17 '14 12:04

Etienne Fesser


1 Answers

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...

like image 116
Patrick Hofman Avatar answered Sep 29 '22 22:09

Patrick Hofman