Importing excel data and finding the number of rows and columns

9 次查看(过去 30 天)
When i use xlsead(filename) i get a warning message saying 'Could not start Excel server for import, 'basic' mode will be used' and then an error message saying 'File contains unexpected record length'
How do i get rid of this? I want to be able to retreive data from the file, find out how many rows and columns there are and eventually access them but I can't seem to do this?

回答(2 个)

Image Analyst
Image Analyst 2014-7-7
If your data is in a tabular format in excel (columns of strings or numbers with column headers as the first row), you can use readtable() instead of xlsread():
t = readtable(filename);
[rows, columns] = size(t);

Mukul Rao
Mukul Rao 2014-7-7
Try
>> x = actxserver(Excel.Application)
If this goes through, then the issue could be with the path; you can restore these to their default values as follows:
>> restoredefaultpath
>> rehash toolbox
>> rehash toolbox cache
In case the above “actxserver” call fails, it may mean that a MATLAB-Excel COM interface could not be established.One main reason why this might occur is that the "actxserver.m" is not on path.To find out whether the correct actxserver.m is being used, execute the following on MATLAB command prompt
>> which actxserver
If this does not point to the correct version of actxserver.m, make MATLAB point to the correct version in order to resolve the issue. To use “xlsread” and “xlswrite”, you need to have a COM server or Microsoft Excel installed on your machine. On Windows COM server installation is done along with Microsoft Excel installation. For Mac OS X, there is no COM server available to date and hence these functions will work only in the basic mode.
This issue may also arise on Windows machines with Click-to-Run editions of Microsoft Office. To check if this is the case, click the "Start" button, then click "Control Panel". Click "Default Programs", then click "Associate a file type or protocol with a program". Check to see if the '.xls' extension is associated with a virtualized version of Microsoft Excel. If it is, the steps on the following Microsoft support page for switching to an MSI-based Office edition may resolve the issue:

标签

Community Treasure Hunt

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

Start Hunting!

Translated by