There is any way to know the dimensions of an excel file (rows, columns) without using xlsread?

15 visualizaciones (últimos 30 días)
There is any way to know the dimensions of an excel file (rows, columns) without using xlsread?
I have very large .csv/.xlsx files and I want to increase a waitbar. My strategy will be make a loop with a percentage of the file to read and then increase the waitbar.... repeating it till the file is completely read.

Respuesta aceptada

Tom
Tom el 19 de Jun. de 2013
You can, but you have to open an Actx server - I wouldn't bother unless you really think it's worth it...
Excel = actxserver('excel.application');
Excel.workbooks.Open(fileName,0,true); %file name must also have path
nCols = Excel.ActiveSheet.UsedRange.Columns.Count;
nRows = Excel.ActiveSheet.UsedRange.Rows.Count;
Excel.Quit
Excel.delete
That will probably need adding to (e.g. specifying a worksheet)
  2 comentarios
dpb
dpb el 4 de Ag. de 2024
NOTA BENE: The above code snippet leaves the Excel file open...it should also close the file before destroying the connection...
Excel = actxserver('excel.application');
Excel.workbooks.Open(fileName,0,true); %file name must also have path
nCols = Excel.ActiveSheet.UsedRange.Columns.Count;
nRows = Excel.ActiveSheet.UsedRange.Rows.Count;
Excel.ActiveWorkbook.Close(0); % close the workbook!!!!
Excel.Quit
Excel.delete
clear Excel % also get rid of no longer valid Excel object hanging around in workspace
It would be better to encapusate the functionality in a function...

Iniciar sesión para comentar.

Más respuestas (1)

David Sanchez
David Sanchez el 19 de Jun. de 2013
NO, there is not a way to do what you need/want.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by