WorkSheet.Dimension giving null reference Exception

Mar 17, 2011 at 9:33 PM

Hi 

 

I get a null reference exception when I am using Dimension on ExcelWorkSheet object

Is there a way to fix this??

 

 

Thanks

Sri

Coordinator
Mar 18, 2011 at 3:19 PM

If the worksheet has no cells the Dimension property returns null.

Mar 18, 2011 at 3:34 PM

No I have cells in the excelsheet but it is still giving me a null value.

The sheet has 170 rows and 6 columns of cells with data

 

I am trying to clear all the cells and write new data 

I have used the Dimension to get the number of modified rows and columns in the excel sheet and it gives me a null reference exception

Coordinator
Mar 18, 2011 at 3:58 PM

Ok, that's strange.

The Dimesion property looks likte this...

                if (_cells.Count > 0)
                {
                    return new ExcelAddressBase((_cells[0] as ExcelCell).Row, _minCol, (_cells[_cells.Count - 1] as ExcelCell).Row, _maxCol);
                }
                else
                {
                    return null;
                }

_cells are all the cells in the worksheet, so you don't have any loaded.

Please provide me with some code to replicate this.