C# code to add hyper link in excel sheet -


hi having excel file containing multiple sheets. 1 of sheets contain hyperlink other sheets.

while using following code have added link when click on link gives error **"refrence not valid"**

code snippet:

private void addhyperlink(workbook xlworkbook,int nfaultcount) {             excel.worksheet xlworksheet = (excel.worksheet)xlworkbook.worksheets.get_item(1);             datetime = datetime.now;          xlworksheet.name = "summary"; //name of sheet containing hyperlink          xlworksheet.select(type.missing); //code select summary sheet          (int = 1; <= nfaultcount; i++)         {             int x = + 9;              string str = "fault code "+i + " of " + nfaultcount;              string strrange1 = "a" + x;              string strrange2 = "a" + x;              string strrange = strrange1 + ":" + strrange2; //location of link               var range = xlworksheet.get_range(strrange);             // strrange1 = "!" + strrange1;             string strp="#" + + " of " +nfaultcount + strrange1;               +" of " nfaultcount==> name of target worksheet             range.cells.hyperlinks.add(range,strp, type.missing, "fault code link", str);         }          xlworksheet.columns["a:b"].autofit(); 

}

i have used following link refrence http://www.experts-exchange.com/programming/languages/.net/q_27912390.html

but giving error refrence not valid.

the error message says hyperlink address invalid.

try generating as:

string strp="#'" + + " of " +nfaultcount + "'!" + strrange1; // sample result: "#'4 of 5'!a3 

instead of

string strp="#" + + " of " +nfaultcount + strrange1; // sample result: #4 of 5a3 

the above assumes target worksheet name "4 of 5".

note need ! character between worksheet name , range name. need enclose worksheet name in single quotes if contains 1 or more spaces.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -