tags:

views:

30

answers:

1

Hi,

I am attempting to hide some rows in an excel sheet using C#.

but the line

deleteRange.EntireRow.Hidden = true;

is giving errors.

The entire code of selecting the range and hiding the rows is given below

string rowCnt = Convert.ToString(excelExportData.Tables["AllVersionDts"].Rows.Count + 8);
string startCell = "A" + rowCnt;
Microsoft.Office.Interop.Excel.Range deleteRange = ws.get_Range(startCell+":A65536",Missing.Value);
deleteRange.EntireRow.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);

deleteRange.EntireRow.Hidden = true;

Please look into this code and say where am I going wrong.

Thanks

+1  A: 

The "Delete" somehow changed your range. Redefine the range right before hidden:

deleteRange = ws.get_Range(startCell+":A65536",Missing.Value);
deleteRange.EntireRow.Hidden = true;
PerlDev
That worked perfectly on the first try. Thank you.
Jagannath Swain
@Jagannath Swain: You can go ahead and accept PerlDev's answer by clicking the hollow check-mark next to this answer.
Otaku