Save Matlab data in Excel with ActiveX
37 ビュー (過去 30 日間)
古いコメントを表示
Joanna Przeworska
2021 年 5 月 7 日
コメント済み: Joanna Przeworska
2021 年 5 月 17 日
Hello,
I need your help as I am not very experienced in linking with Excel through ActiveX. Below I attach the code I managed to write so far (based on suggestions from Internet). My goal is to use template.xlsx which contains desired formatting, write values inside and save everything under different name, e.g. file.xlsx.
I would appreciate if you help me complete this code.
% Specify file name
file = 'P:\WPM\CCB\Notatka\RF\template.xlsx'; % This must be full path name
% Open Excel Automation server
Excel = actxserver('Excel.Application');
Workbooks = Excel.Workbooks;
% Make Excel visible
Excel.Visible=1;
% Open Excel file
Workbook=Workbooks.Open(file);
% Specify sheet number, data, and range to write to
sheetnum=1;
data = SECTORS.PNFS.Total{1:end,1:end}; % use a cell array if you want both numeric and text data
range = 'B9:L77';
% Make the first sheet active
Sheets = Excel.ActiveWorkBook.Sheets;
sheet1 = get(Sheets, 'Item', sheetnum);
invoke(sheet1, 'Activate');
Activesheet = Excel.Activesheet;
% Put MATLAB data into Excel
ActivesheetRange = get(Activesheet,'Range',range);
set(ActivesheetRange, 'Value', data);
0 件のコメント
採用された回答
Cris LaPierre
2021 年 5 月 7 日
3 件のコメント
Cris LaPierre
2021 年 5 月 14 日
So what is the missing piece? Saving it under a new name? Use the 'saveas' method instead of 'save'.
Workbooks.SaveAs(newfile);
If you want a solution guaranteed to work for your specific case, share your data and template files for us to use in our testing. You can attach them using the paperclip icon.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!