我在D:\目录中有多个excel文件,这些文件名以" gt"开头。字符我需要删除这些文件中的所有空行,仅限Sheet1,并以其他名称存储处理过的文件,
问:\以下代码已成功删除所有空行,但是从单个文件中删除,我们如何将其应用于D:\目录中的所有文件,其名称以" gt"开头。人物?
我在上面提到的以下代码......
[~, ~, data] = xlsread('D:\gt1.xls','Sheet1');
data(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x), data)) = {''};
ii = 1;
while true
try
if any(strcmp('', data(ii,:))) % find rows with empty cell
data(ii,:) = []; % remove the row
else
ii = ii+1;
end
catch
break % When the process goes beyond the end, stop the loop.
end
end
xlswrite('D:\result1.xls', data)
我为所有excel文件长时间尝试此代码
FileNames=dir('D:\gt*.xls');
for i=1:length(FileNames)
FileToLoad=FileNames(i).name;
[~, ~, data] = xlsread(FileToLoad,'Sheet1');
data(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x), data)) = {''};
ii = 1;
while true
try
if any(strcmp('', data(ii,:))) % find rows with empty cell
data(ii,:) = []; % remove the row
else
ii = ii+1;
end
catch
break % When the process goes beyond the end, stop the loop.
end
end
xlswrite('D:\result[ii].xls', data)
end
希望获得像
这样的输出 gt1.xls file store as result1.xls file ;
gt2.xls file store as result2.xls file ;
and so on ....