- Use the search box at the top of Task Manager to search for "excel" and confirm that only one Excel process is active. This ensures that you connect to the intended target workbook.
- You can also use the following MATLAB code to programmatically check how many Excel processes are running before running script:
How can I paste a MATLAB figure into an existing Excel file using MATLAB R2025a on Windows?
6 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2025-11-26,0:00
回答: MathWorks Support Team
2025-12-2,21:45
I am trying to automate the process of plotting and pasting a MATLAB figure into an already open Excel file using MATLAB R2025a on Windows. I want to make sure I connect to the correct Excel process and avoid errors when using the "actxGetRunningServer" function. I am currently using Microsoft Excel for Microsoft 365, Version 2509 (64-bit). How can I reliably paste my figure into the Excel workbook?
采纳的回答
MathWorks Support Team
2025-11-26,0:00
Using COM to connect to Excel is a great way to accomplish this. Note that this approach will not work for non-Windows machines, since COM is used.
An Excel process may have multiple workbooks and worksheets open simultaneously. Before running your MATLAB code, make sure that only the specific workbook you want to use is open, and that the desired worksheet is active - that is, selected and visible above any other worksheets. The script relies on the correct workbook and worksheet being active in order to paste the figure into the intended location.
Attached is a simple script ("excel_figure_demo.m") that shows how one can connect to the Excel spreadsheet and add a figure from MATLAB.
Before running the script, make sure only one Excel process is running:
>> [~, result] = system('tasklist /FI "IMAGENAME eq EXCEL.EXE"');
>> numExcelProcesses = count(result, 'EXCEL.EXE');
>> disp(['Number of Excel processes running: ', num2str(numExcelProcesses)]);
Note: The script above was tested and verified using MATLAB R2025a, and Microsoft Excel for Microsoft 365, Version 2509 (64-bit).
0 个评论
更多回答(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!