9

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 ?

  • possible duplicate of [Dispose, when is it called?](http://stackoverflow.com/questions/2871888/dispose-when-is-it-called) –  Apr 17 '14 at 12:44
  • 3
    @mehow This was a library specific question. Examples found on EPPlus website doesn't mention that Dispose has to be called ; that's why I asked. – Etienne Fesser Apr 17 '14 at 12:50

1 Answers1

6

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

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325