Update an Excel file after each Matlab calculation
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Stephen23
el 25 de Abr. de 2024
Editada: Stephen23
el 25 de Abr. de 2024
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.
2 comentarios
Stephen23
el 25 de Abr. de 2024
"Do you know a function or code line to do this in matlab?"
Yes: the ACTXSERVER method RUN, that you use to run a macro that calls the worksheet method CALCULATE. Exactly as per my answer.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
