Warning: An error occurred while reading worksheet 2016: Undefined function 'Select' corresponding to an input argument of type 'Interface.00020846_0000_0000_C000_00000000
Show older comments
clc
clear
% 让用户选择要读取的 Excel 文件
[filename, pathname] = uigetfile({'*.xls;*.xlsx','Excel Files (*.xls, *.xlsx)'},'选择要读取的Excel文件');
% 检查用户是否取消了选择
if isequal(filename,0)
disp('用户取消了文件选择');
return;
end
% 构造完整的文件路径
fullfile = fullfile(pathname, filename);
% 获取 Excel 文件中的所有工作表信息
[~,sheets] = xlsfinfo(fullfile);
% 创建一个单元格数组来存储所有工作表的数据
all_data = cell(length(sheets), 1);
% 逐个读取每个工作表的数据
for i = 1:length(sheets)
try
data = xlsread(fullfile, sheets{i});
all_data{i} = data;
catch exception
warning(['在读取工作表 ', sheets{i}, ' 时发生错误:', exception.message]);
end
end
% 显示每个工作表的数据大小
for i = 1:length(sheets)
if ~isempty(all_data{i})
disp(['工作表名:', sheets{i}, ',数据大小:', num2str(size(all_data{i}))]);
end
end

Answers (0)
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!