Hyperlinks to worksheet with spaces in name

Hello,

I just started using Aspose Cells to generate Excel documents. So far I have been impressed with how easy the system is to use.

In my code I am generating multiple worksheets in a workbook. The first sheet is like a table of contents, with hyperlinks to other sheets in the Excel document. The hyperlinks work fine except when a sheet name has one or more spaces in its name. Spaces in a sheet name does not appear to be a problem in Excel, just Aspose.

The code for generating the hyperlinks looks like this:

string sheetName = workbook.Worksheets[indexSheet].Name;

string docLink = sheetName + "!A9"; // Works if sheetName == "sheet2" but not "sheet two", for example.

int indexLink = worksheet.Hyperlinks.Add(row, col, 1, 1, docLink);

Hyperlink hyperlink = worksheet.Hyperlinks[indexLink];

hyperlink.TextToDisplay = linkText;

hyperlink.ScreenTip = "View worksheet " + sheetName;

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, you may need to change your code a bit to get your desired result. Please modify your code as following.

string sheetName = workbook.Worksheets[indexSheet].Name;

string docLink = "'" + sheetName + "'!A9"; // Works if sheetName == "sheet2" but not "sheet two", for example.

int indexLink = worksheet.Hyperlinks.Add(row, col, 1, 1, docLink);

Hyperlink hyperlink = worksheet.Hyperlinks[indexLink];

hyperlink.TextToDisplay = linkText;

hyperlink.ScreenTip = "View worksheet " + sheetName;

Thank You & Best Regards,

Thanks for the quick response. Your suggestion to use ' as a delimiter around the sheet name does the trick. I had tried to use "" and even [] around the name but did not think to try ''.

Regards,

Sig Isaac