ActiveX Excel Awkward Behavior
Mostrar comentarios más antiguos
Hi,
I am working on something for which I need to read many sheets from a single excel file. The file is on the large side, using the standard readcell(...) was too slow opening an instance of excel for each sheet. I instead ventured into using ActiveX instead, something I am only slightly familiar with.
Based on several posts I found online, I put together the following bit of code:
hExcel = actxserver('Excel.Application');
hExcel.visible = 1;
hExcel.DisplayAlerts = 0;
Wkbk = hExcel.Workbooks.Open(filePath);
for iter = 1:length(loops)
% Looping over Wkbk sheets
data = Wkbk.Worksheets.Item(sheetTitles(iter)).UsedRange.Value;
end
Wkbk.Close;
hExcel.Quit;
hExcel.delete;
The above runs properly, however there are some very strange caveats I I dont understand.
- The above code ONLY works if visibility is set to 1. I would prefer this run in the background without the user seeing it.
- Even with DisplayAlerts set to 0, I cannot close the opened Excel application without manually pressing the "Save" or "Do not Save" button on the window that appears.
Thank you guys for the help! The answers on here are always very insightful!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!