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

WorkSheet.Dimension giving null reference Exception

Mar 17, 2011 at 8:33 PM



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

Is there a way to fix this??





Mar 18, 2011 at 2:19 PM

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

Mar 18, 2011 at 2: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

Mar 18, 2011 at 2: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);
                    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.