Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
// Resize the columns
             oRange = oSheet.get_Range(oSheet.Cells[1, 1],
             oSheet.Cells[rowCount, dtFinal.Columns.Count]);
             oRange.EntireColumn.AutoFit();


Hi. I have an error of RuntimeBinderException was unhandled at
C#
get_range(oSheet.Cells[1,1]


How do I solve this issue? Any help would be gladly appreciated! Thank you!

What I have tried:

tried to search for quick answers on online but to no avail
Posted
Updated 20-Mar-18 23:51pm
Comments
Richard MacCutchan 21-Mar-18 5:16am    
Catch the exception and look at the content, especially messages and inner data. Also we have no context for the above code. Have you opened the correct worksheet, and does it contain entries for the listed cell?
Member 13650651 21-Mar-18 5:22am    
Yes, I managed to open the correct worksheet and the contents in the worksheet.
Richard MacCutchan 21-Mar-18 5:23am    
You still need to catch the exception and find out exactly what it is complaining about.

1 solution

Put a try/catch block around your code:

try
{
    oRange = oSheet.get_Range(oSheet.Cells[1, 1],
    oSheet.Cells[rowCount, dtFinal.Columns.Count]);
    oRange.EntireColumn.AutoFit();
}
catch (Exception ex)
{  // put a breakpoint here, and when your code throws the exception, inspect "ex"
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900