xlswrite using different names

2 次查看(过去 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.

采纳的回答

Walter Roberson
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
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');
Raúl
Raúl 2013-2-27
Thanks a lot Walter.
It works.
Raúl.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by