c# - Worksheet get_Range throws exception -


i'm using c# manipulate excel worksheet. following 2 pieces of code should work same, 1 works , other throws exception. wonder why.

this works:

orange = (excel.range)osheet.get_range("a1","f1"); orange.entirecolumn.autofit(); 

this throws exception:

orange = (excel.range)osheet.get_range(osheet.cells[1, 1],osheet.cells[4,4]); orange.entirecolumn.autofit(); 

exception:

runtimebinderexception occurred. "object" not contain definition 'get_range' 

the osheet instantiated follows:

excel.worksheet osheet = new excel.worksheet(); 

am supposed instantiate both differently?

it looks exception thrown osheet.cells[1, 1] , osheet.cells[4, 4] used arguments get_range.

by doing following, there no exception:

excel.range c1 = osheet.cells[1, 1]; excel.range c2 = osheet.cells[4, 4]; orange = (excel.range)osheet.get_range(c1, c2); orange.entirecolumn.autofit(); 

so might related osheet.get_range functionality. receives object argument, therefore might try invoke get_range method on arguments receive internal cell, , up-cast range object done compiler might hide method call.

if need cells definition row/column - try using above approach


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -