Writing a Hyperlink in Excel with Matlab

33 views (last 30 days)
Christian Sellmann
Christian Sellmann on 23 Mar 2021
Answered: Ananya Tewari on 26 Mar 2021
i tried to write a Hyperlink in Excel. I create a string with '=Hyperlink("Link")'.
When i write the string into the excel file it does not execute the funtion.
stringToInsertIntoExcel = strcat('=HYPERLINK("',F,'")');
So writing the Link into the excelfile is not the problem. The Problem ist, that the Function =Hyperlink() does not execute.
Thank you for you time
Mario Malic
Mario Malic on 23 Mar 2021
This is the character array that works with the hyperlink that you should write into Excel. I am not sure whether I like it being placed to cell, then cell2struct, then struct2table, maybe you have some issue there? Is anything written in the cell in Excel, if yes, can you paste the value of one cell (you can hide the link)?
hExcel.ActiveSheet.Range("A6").Value = '=HYPERLINK("https://www.mathworks.com")'

Sign in to comment.

Answers (1)

Ananya Tewari
Ananya Tewari on 26 Mar 2021
I understand you want to insert Hyperlink in an excel through MATLAB. The writetable() command is not able to execute the "=HYPERLINK()" and you need to manually make it as a function to execute. Creating excel object can help you achieve the desired output:
exl = actxserver('excel.application');
exlWorbook = exl.Workbooks;
excelFile = exlWorbook.Open('Location\hyperlinks.xlsx');
exlSheet1 = exlFile.Sheets.Item('Sheet1');
rngObj = exlSheet1.Range('A1'); %Cell where you want add the hyperlink
exlSheet1.HyperLinks.Add(rngObj, 'https://google.com');
Another possible way of doing the same is by using xlswrite(), but it is not a recommended way.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!