how to close an excel file
149 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
pradeep kumar
el 21 de Nov. de 2014
Comentada: Image Analyst
el 30 de Mzo. de 2023
Hellow everyone . i am using
winopen('myfile.xlsx')
to open an excel file , after doing some modification, i want to close the excel file in order to overwrite the existing data by
xlswrite('myfile.xlsx', my_modified_data )
but sometimes i forgot to close the file manually in between and MATLAB generates an error . Is there any way to automatically close the excel file(by some command like winclose or something like that) before writing into it . Thank You all .
0 comentarios
Respuesta aceptada
Image Analyst
el 21 de Nov. de 2014
Yes. You can use actxGetRunningServer() to connect to Excel and shut it down.
9 comentarios
Ihaveaquest
el 30 de Mzo. de 2023
works for powerpoint as well - theres not much info online for how to with powerpoint
import mlreportgen.ppt.*
taskToLookFor = 'Powerpnt.exe';
% Now make up the command line with the proper argument
% that will find only the process we are looking for.
commandLine = sprintf('tasklist /FI "IMAGENAME eq %s"', taskToLookFor)
% Now execute that command line and accept the result into "result".
[status result] = system(commandLine)
% Look for our program's name in the result variable.
itIsRunning = strfind(lower(result), lower(taskToLookFor))
%closes powerpoints if they are open so system does not crasah when it
%tries to open a new PP
if itIsRunning
if exist('Plotted Circulator', 'file')==0
system('taskkill /F /IM POWERPNT.EXE');
end
else
end
Image Analyst
el 30 de Mzo. de 2023
@Ihaveaquest if Excel is open with several sheets, you can use
Excel = actxGetRunningServer('Excel.Application');
to get a handle to the Excel server, then use Excel to save the active sheet and close it.
Excel.ActiveWorkbook.Save;
Excel.ActiveWorkbook.Close(false); % The 'false' argument prevents the popup window from showing, forcing the closure without user intervention.
Más respuestas (1)
Artem Smirnov
el 19 de En. de 2017
Try this:
close all
1 comentario
Image Analyst
el 19 de En. de 2017
And when/if you do, you'll see that close does not shutdown other processes and applications like Excel.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!