本文使用素材含代码测试用例等
MATLAB读写excel文件历程含,内含有测试代码资源-CSDN文库
打开文件
使用uigetfile函数过滤非xlsx文件,找到需要读取的文件,首先判断文件是否存在,如果文件不存在,程序直接返回,存在记录下文件的路径
[file,path] = uigetfile('*.xlsx');
if isequal(file,0)
   disp('User selected Cancel');
   return;
else
   disp(['User selected ', fullfile(path,file)]);
end
 
f_path = fullfile(path,file);
读取数据
[DATA] = xlsread(f_path);写入数据
xlswrite(f_path,DATA,'sheet2','A2:D1153');函数介绍


完整代码
clc;
clear;
 
[file,path] = uigetfile('*.xlsx');
if isequal(file,0)
   disp('User selected Cancel');
   return;
else
   disp(['User selected ', fullfile(path,file)]);
end
 
f_path = fullfile(path,file);
 
[DATA] = xlsread(f_path);
 
xlswrite(f_path,DATA,'sheet2','A2:D1153');
测试结果

提供测试文件



















