c# - Why do I get "Invalid args" at runtime with this code? -


i've got code conditionally format cell after has been assigned to, based on value contains:

var avgweeklydeliveriescell = (excel.range)_xlsheet.cells[curdelperfrow,      avg_weekly_deliveries_column]; avgweeklydeliveriescell.value2 = string.format("=round(average(c{0}:i{0}),       2)", curdelperfrow); avgweeklydeliveriescell.numberformat = "#,##0.00";     conditionallyhighlight(avgweeklydeliveriescell.value2,    _xlsheet.usedrange.row);  private void conditionallyhighlight(string cellval, int rowindex) {     int col_k_index = 11;     float avgweeklydelivery = float.parse(cellval,          cultureinfo.invariantculture);     if (avgweeklydelivery > delsperweek)     {         excel.range celltohighlight = (excel.range)_xlsheet.cells[rowindex             col_k_index];         celltohighlight.interior.color = out_of_bounds_highlight_color;     } } 

the problem cellval; seems string, i'm assigning results of string.format() call cells' value2 property, , passing (value2) method conditionally format cell.

it compiles, @ runtime fails "invalid args" message. why, , how can fix it?

after setup formula value2, property returns evaluated value, int/double in case. not need parse value.

just change parameter cellval type double:

private void conditionallyhighlight(double cellval, int rowindex) {     int col_k_index = 11;     if (cellval > delsperweek)     {         excel.range celltohighlight = (excel.range)_xlsheet.cells[rowindex,             col_k_index];         celltohighlight.interior.color = out_of_bounds_highlight_color;     } } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -