필터 지우기
필터 지우기

writetable() does not close file after writing

조회 수: 28 (최근 30일)
Tobias Pettke
Tobias Pettke 2020년 12월 9일
답변: Tobias Pettke 2020년 12월 10일
When using writetable Matlab opens an Excel file and I can see how columns are being filled.
However, the created file is not closed afterwards which it used to do but doesn't anymore.
Since the code may run in a loop for several days I may not always be around to close these files manually
To kill Excel entirely is not desireable as other Excel files, unrelated to the MatLab code, may be open.
I did try fopen and fclose but to no avail.
Any ideas? Is it possible that the issue lies in the Excel setting?
This is my code
% Export table output
disp(' > Output exportieren')
outputpath='C:\drive\folder\';
outputname='Table_output';
outputfile=strcat(outputpath,outputname,'_',datestr(now,'dd.mm.yyyy'),'.xlsb');
writetable(E,outputfile)
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 12월 9일
You could try
writetable(E, outputfile, 'useexcel', true)
but I am not clear that would help.
In the release you are using, the default for useexcel is false, so it should not be invoking Excel. But I cannot say at the moment whether it leaves the file open internally for efficiency reasons; I would not rule it out.

댓글을 달려면 로그인하십시오.

답변 (2개)

Tobias Pettke
Tobias Pettke 2020년 12월 10일
Thanks for the help.
I found the issue was in an earlier writetable() instance, though.
There I changed the sheet name and the intended name was in double quotes.
Previously, the first Excel file was not closed after writing and later exports remained open as well.
Before
writetable(Table, filename, 'Sheet', "My Sheet Name")
Now
writetable(Table, filename, 'Sheet', 'My Sheet Name')

Théophane Dimier
Théophane Dimier 2020년 12월 9일
Using an actxserver (see here ) instead of Matlab built-in function would give you complete control on which file is open or not, and you could even close excel directly from your matlab code, without having to kill the process.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by