xlswrite using different names
5 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm trying to create a loop where some data is read in one file and writes it in the copy of a template. The output excel file, should be one generic part plus the name of the source file. I don't know why, but i'm getting some kind of error..
%Open multiple files from a folder
myFolder = 'C:\Users';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.xls');
xlsFiles = dir(filePattern);
for k = 1:length(xlsFiles)
baseFileName = xlsFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
drawnow; % Force display to updaclc
[~,~,RAW] = xlsread(fullFileName,1,'N2:N300'); % EPC
[~,~,RAW2] = xlsread(fullFileName,1,'O2:O300'); % RSSI MEAN
[~,~,RAW3] = xlsread(fullFileName,1,'U2:U300'); % READ COUNT
copyfile('C:\Users\U95511\Dropbox\UPF\Matlab\RV\DP\INVENTARIOPISTOLA_template.xls','C:\Users\U95511\Dropbox\UPF\Matlab\RV\DP\INVENTARIOPISTOLA_.xls')
new=1234;
xlswrite(sprintf('C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_%s.xls',new),RAW,2,'A5');
xlswrite(sprintf('C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_%s.xls',new),3,2,'B5:B300');
xlswrite(sprintf('C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_%s.xls',new),RAW2,2,'F5');
xlswrite(sprintf('C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_%s.xls',new),RAW3,2,'G5');
end
The error is that one.
Warning: Escape sequence 'U' is not valid. See 'help sprintf' for valid escape sequences.
> In DPtoInventoryV3 at 47
Error using xlswrite (line 220)
Invoke Error, Dispatch Exception:
Source: Microsoft Office Excel
Description: Error en el método SaveAs de la clase Workbook.
Help File: C:\Program Files (x86)\Microsoft Office\Office12\3082\XLMAIN11.CHM
Help Context ID: 0
Error in DPtoInventoryV3 (line 47)
xlswrite(sprintf('C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_%s.xls',new),RAW,2,'A5');
Could please somebody help me?
Thanks a lot.
BR,
Raúl.
0 个评论
采纳的回答
Walter Roberson
2013-2-26
xlswrite(sprintf('%s.xls', 'C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_',new),RAW,2,'A5');
or
xlswrite(['C:\Users\U95511\Dropbox\UPF\Matlab\RV\INVENTARIOPISTOLA_' new '.xls'], RAW, 2, 'A5')
3 个评论
Walter Roberson
2013-2-27
newfilename = sprintf('%s%04d.xls', 'C:\Users\U95511\Dropbox\UPF\Matlab\RV\DP\INVENTARIOPISTOLA_', new);
copyfile('C:\Users\U95511\Dropbox\UPF\Matlab\RV\DP\INVENTARIOPISTOLA_template.xls', newfilename);
xlswrite(newfilename, RAW, 2, 'A5');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!