Reputation: 1902
In excel COM interop (C#), what is the difference between:
_sheet = (Excel._Worksheet)_wb.Worksheets["SheetName"];
and
_sheet = (Excel._Worksheet)_wb.Sheets["SheetName"];
?
Upvotes: 12
Views: 4737
Reputation: 10899
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.
Upvotes: 16