Как получить номер ячейки используемой в данный момент гиперссылки в Excel (Matlab) - PullRequest
0 голосов
/ 26 сентября 2018

Я хочу использовать гиперссылку в Excel, чтобы открыть функцию Matlab, и использовать Data1.mat-Data6.mat для расчета в этой функции.Я думал, что я могу использовать путь к файлам Data.mat в качестве имени гиперссылки, и сама гиперссылка откроет функцию.Я нашел функцию, которая извлекает все гиперссылки, их имена и местоположения в листе Excel.Однако я не могу понять, как Matlab мог найти используемую в настоящее время гиперссылку.

excel sheet

Функция xlsgethyperlinks.m выдает список всех гиперссылок на листе, но янеобходимо найти местоположение используемого в данный момент листа в листе.

      function [name, links, locations] = xlsgethyperlinks(file, sheet)
 %retrieve all hyperlinks and their location in an excel worksheet
 %syntax:
 %    [links, locations] = xlsgethyperlinks(file);
 %    [links, locations] = xlsgethyperlinks(file, sheet);
 %with:
 %    file: full path of the excel workbook (scalar string / char vector)
 %    sheet: name or index of worksheet (scalar string / char vector / 
 %scalar positive integer). Default is 1
 %    links: column cell vector of hyperlink targets in the order returned % 
 %by excel
 %    locations: column cell vector of char vectors containing the location 
 %of the hyperlinks in the sheet, in RC format
 %    Author: G. de Sercey
 %    BSD license
 if nargin < 2
   sheet = 1;
 end
 %todo: add input validation
 %The code starts excel, load the workbook, then iterates over all the 
 %hyperlinks in the worksheet storing the hyperlink address and the range 
 %address of the hyperlinks.
 %excel is closed automatically by the onCleanup when the function 
 %terminates 
 %(normally or due to errors).
 excel = actxserver('Excel.Application');
 cleanup = onCleanup(@() excel.Quit);
 workbook = excel.Workbooks.Open(file);
 worksheet = workbook.Worksheets.Item(sheet);
 hyperlinks = worksheet.Hyperlinks;
 links = cell(hyperlinks.Count, 1);
 locations = cell(hyperlinks.Count, 1);
 name = cell(hyperlinks.Count, 1);

 for hidx = 1:hyperlinks.Count
   hyperlink = hyperlinks.Item(hidx);
   links{hidx} = hyperlink.Address;
   locations{hidx} = hyperlink.Range.Address;
   name{hidx} = hyperlink.Name;

   end
 end
...