This project has moved. For the latest updates, please go here.

Row by row shows varying lengths in C#

Sep 19, 2013 at 3:01 PM
Hi.

My application is reading an excel sheet from an external vendor. The excel sheet looks fine, but it appears that it was edited using some feature in excel which confuses my epplus based code.

This two consecutive code lines returns two different numbers (on the same excel sheet).
pck1.Workbook.Worksheets["MACH_IO"].Cells["a279:bb279"].Count();
pck1.Workbook.Worksheets["MACH_IO"].Cells["a280:bb280"].Count();
since they cover the same amount of columns, the numbers should be the same, AFAICT.

Question 1: What can cause this? Merged cells? Cells with "null" content? Special content types (eg Formulas)?
Question 2: How do I compensate? I discovered this because .ElementAt() started returning the wrong stuff. It is very important that I am reading the visual column.
Question 3: I assume that some cells are missing. If this, for example, is "f280", what will happen if I try to access it directly.

Thank you.
Editor
Sep 20, 2013 at 8:32 PM
I've never needed to take a look inside it, but I think only initialized cells will be in dictionary, if you try to access it directly will create a new entry on cell´s dictionary. So, If I am right, you can have a lot of "roles" inside your cells collection. Why you need to use ElementAt? Maybe you can try a linq querie.