matlab代码如下:
clear;
clc;
filePath=uigetdir({},'choose your filepath'); %获取excel文件存储目录
getFileName=ls(strcat(filePath,'\*.xl*')); %获取所选目录下的文件名
fileName = cellstr(getFileName); %将string数组转为cell数组
if isequal(getFileName,'')%防止选择空文件夹
msgbox('no excel file in the path you selected');
else
mkdir(strcat(filePath,'\output'));%新建输出文件夹
waiting=waitbar(0,'excuting...,please wait!');%进度条
for i=1: length(fileName) %foreach your files
[excelData,str] = xlsread(strcat(filePath,'\',fileName{i}));%读取excel
xlswrite(strcat(filePath,'\output\output.xlsx'),str,strcat('Sheet',num2str(i)), 'A1');%将读取的工作表表头写入excel
xlswrite(strcat(filePath,'\output\output.xlsx'),excelData,strcat('Sheet',num2str(i)), 'A2');%将读取的工作表数字写入excel
end
close(waiting)%关闭进度条
disp 'you can find output file there:'
outputPath = strcat(filePath,'\output\output.xlsx')
msgbox(strcat('finished,get output file in:',outputPath),'Success','Help');%prompt message
end