Update an Excel file after each Matlab calculation
Show older comments
Dear everyone,
I need to communicate between Matlab file and a very complicated excel file with several sheets which are connected to each other. All Excel sheets will be calculated after the matlab result was filled in one certain cell in Excel. Does anybody know a code line in Matlab how to refresh the whole excel file automatically from Matlab (last code line)? Excel is not able to this by its own.
Thank you very much!
add_in_path = 'xxx'; % Ordnerpfad
add_in_filename = 'REFPROP.xla'; % Dateiname
%---------- Excel connection
file_path = 'xxx'; % Ordnerpfad
filename = 'xxx'; % Dateiname
spreadsheet_name = 'xxx'; % Name des Tabellenblatts
% Import area
spreadsheet_range = 'xxx'; % Zellenbereich
%% Start
%--- COM-Server start
[Excel, File] = Excel_interaction_Start_COM_Server(add_in_path, add_in_filename, file_path, filename);
%% Matlab calculation ongoing
%Write the result in the Excel file
xlswrite1(File,rawData_mod,spreadsheet_name,spreadsheet_range_export);
%% Excel refresh ?????????
3 Comments
Dyuman Joshi
on 25 Apr 2024
Secondly, Is it necessary to update the file after each calculation or the calculations can be performed all at once and then the file can be updated?
Answers (1)
You can use a COM server to trigger Excel to recalculate the worksheets:
A basic outline:
- make sure you use a macro-enabled Excel workbook e.g. XLSM.
- write a VBA macro that calculates the worksheets/ranges that you require using e.g. https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.calculate(method)
- open a COM server from MATLAB:
- write the value/s, then
- call the VBA macro.
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!