How to close Excel-file after writetable()?

47 ビュー (過去 30 日間)
Reinhard Palaver
Reinhard Palaver 2016 年 10 月 10 日
コメント済み: Martin 2025 年 1 月 15 日
I want to use writetable() for an Excel-file in a for-loop. But at the second loop it stops with an error, because the first file is still open and there is no permission. Before I'd open a new folder for the new excel-file, but it doesn't work in this way now, because the file is still open.

採用された回答

Image Analyst
Image Analyst 2016 年 10 月 10 日
編集済み: Image Analyst 2016 年 10 月 10 日
I got this from the Mathworks directly:
You can use the following SYSTEM command via MATLAB to kill the process:
>> system('taskkill /F /IM EXCEL.EXE');
  5 件のコメント
Md Bhuyian
Md Bhuyian 2020 年 6 月 25 日
I created an excel file named Comparison.xlsx. How do I only close that excel uding this command?
Martin
Martin 2025 年 1 月 15 日
have a look at the answert above from @Reinhard Palaver, this is basically what you want

サインインしてコメントする。

その他の回答 (2 件)

Reinhard Palaver
Reinhard Palaver 2016 年 10 月 11 日
Now I've an addtional problem. In a for-loop I've to use wait, until the batch is finished, otherwise it doesn't work in they way I want to have. And it's closing "all" excelfiles.
So now I'm looking for a function to close only the specific file after writing.

Walter Roberson
Walter Roberson 2016 年 10 月 11 日
Use table2cell() to create a cell array, and use xlswrite1() from the File Exchange, as that gives you an interface in which you have specific control over closing the spreadsheet.
  5 件のコメント
Md Bhuyian
Md Bhuyian 2020 年 6 月 25 日
I am getting the following error:
Undefined function or variable 'workbooks'
Image Analyst
Image Analyst 2020 年 6 月 26 日
You must have changed the file. There is no workbooks variable in the attached function. You forgot to give the complete error which included the line of code so I don't know how you modified the function. Nevertheless, that demo is from 4 years ago and I have a new one, which I'm attaching here. And I just ran this so I know it works.
Plus I attached a second, separate demo showing how to put a formula into an Excel cell.

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by