Opening an excel file, writing to it and closing it does not
56 次查看(过去 30 天)
显示 更早的评论
% Name existing Excel file
ExcelOut='c:\UNSW\RESEARCH_ACTIVE\BP_Research\BP_UP_DOWN_INVASIVE\CRH_Data_NEW_10H.xlsx';
excelWorkbook=Excel.workbooks.Open(ExcelOut) % Open Excel
RANGE=RowCol(in+4,23); % Subroutine to define start of where to begin writing
writecell(A,ExcelOut,'Sheet',1,'Range',RANGE,'UseExcel',true,'WriteMode','inplace'); % Write to file
Excel.ActiveWorkbook.Save(); % Save Excel File
excelWorkbook.Close(false); % Close Excel File
Excel.Quit; % Quit Excel file. Release resource
Get multiple error messages in MATLAB R2020b
ie
Unable to resolve the name Excel.ActiveWorkbook.Save.
0 个评论
采纳的回答
Walter Roberson
2025-12-9,14:00
excelWorkbook=Excel.workbooks.Open(ExcelOut) % Open Excel
Excel.ActiveWorkbook.Save(); % Save Excel File
The names must match. You need
excelWorkbook.ActiveWorkBook.Save();
7 个评论
dpb
2025-12-9,23:30
" to write the command system('taskkill /F /IM EXCEL.EXE') at the very start of my program"
I would strongly recommend to NOT leave that permanently; once you killed the zombie processes that had the other files locked, there's no need and it will add to the overall overhead to have to restart Excel.
更多回答(2 个)
dpb
2025-12-9,12:55
编辑:dpb
2025-12-9,14:57
You're mixing high-level MATLAB sritecell with code for direct ActiveX/COM interaction with Excel.
You don't need ActiveX here, anyway, writecell and the others (-table, -matrix, ...) handle all the opening and closing of the Excel file internally. Just
% Name existing Excel file
ExcelOut='c:\UNSW\RESEARCH_ACTIVE\BP_Research\BP_UP_DOWN_INVASIVE\CRH_Data_NEW_10H.xlsx';
RANGE=RowCol(in+4,23); % Subroutine to define start of where to begin writing
writecell(A,ExcelOut,'Sheet',1,'Range',RANGE,'UseExcel',true,'WriteMode','inplace'); % Write to file
is all you need.
Also take out the other ActiveX code not shown unless you are going to do things such as formatting the sheet in ways that aren't supported by the builtin read/write functions. If that is the intent, then wait until after have written the data and then open the file with ActiveX or forego using writecell and do it all with ActiveX.
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!