Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Worksheets and Sheets in Excel interop

In excel COM interop (C#), what is the difference between:

_sheet = (Excel._Worksheet)_wb.Worksheets["SheetName"];

and

_sheet = (Excel._Worksheet)_wb.Sheets["SheetName"];

?

like image 411
Pat Mustard Avatar asked Jan 08 '13 09:01

Pat Mustard


1 Answers

Sheets can contain other "Sheets" than Worksheets - Worksheets are not the only possibiliity. E. g. there where Sheets which only contained diagrams, but no Cells. They are not much in use today. So, to be save it is best to stick to the Worksheets property, because this only gives you worksheets which have a documented format. With bad luck, sheet could contain a Sheet which differs from your expectations. I doubt that there are many "non-worksheets" left in the wild, but you never know and Microsoft may introduce more sheet-variants.

like image 71
Christian Sauer Avatar answered Oct 18 '22 15:10

Christian Sauer