writecell does not work properly after invoking and closing actxserver

11 ビュー (過去 30 日間)
Johannes Korsawe
Johannes Korsawe 2022 年 4 月 19 日
回答済み: Chetan 2023 年 11 月 14 日
Hi folks,
i have some strange behavior after switching to office 365.
My former workflow, which consists of a huge number of alternating commands involving writecell, writematrix and starting and deleting excel via actxserver (Excel = actxserver('Excel.Application');doSomeStuff.m;invoke(Workbook, 'Save');invoke(Excel, 'Quit');delete(Excel);), happens to crash/stop due to "unable to write to file" error.
Indetail, the error message says
Unable to write to file 'C:\Users\ekorsaw\Desktop\check.xlsx'. You may not have write permissions or the file may be open by another application.
This did not happen before changing to office365.
Any idea how to force matlab to close the excel document after each access command?

採用された回答

Chetan
Chetan 2023 年 11 月 14 日
You're experiencing issues with the "actxserver" and file permissions, typically when an Excel file is open, locked for editing, or syncing with Office 365/Onedrive.
Here are some solutions:
  • Add a delay: After quitting Excel, pause your script to let the system release the file.
  • Check if the file is locked: Use "fopen" to check the file's status before writing to it. If it's locked, pause and retry.
  • Disable autosave in Excel: If files are syncing to OneDrive or SharePoint, turning off autosave might help. Remember to manually save your changes.
Hope it Helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by