How to close Excel-file after writetable()?
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (2)
Reinhard Palaver
il 11 Ott 2016
0 voti
Walter Roberson
il 11 Ott 2016
0 voti
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 Commenti
Reinhard Palaver
il 12 Ott 2016
Walter Roberson
il 12 Ott 2016
You can deduce it from the Description -- you would invoke the workbook save function when you were finished writing, and then invoke the workbook close function to close that connection. Eventually you tell the excel session to quit, after you have written out all the files.
Image Analyst
il 12 Ott 2016
% Open Excel
Excel = actxserver('Excel.Application');
excelWorkbook = Excel.workbooks.Open(excelFullFileName);
Excel.visible = true; % Make Excel appear so we can see it, otherwise it is hidden.
% Call xlswrite1().....
% Save the workbook
Excel.ActiveWorkbook.Save();
% Close the workbook.
excelWorkbook.Close(false);
% Shut down Excel.
Excel.Quit;
See attached demo.
Md Bhuyian
il 25 Giu 2020
I am getting the following error:
Undefined function or variable 'workbooks'
Image Analyst
il 26 Giu 2020
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.
Categorie
Scopri di più su Spreadsheets in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!