Effacer les filtres
Effacer les filtres

xlswrite using different names

3 vues (au cours des 30 derniers jours)
Raúl
Raúl le 26 Fév 2013
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Fév 2013
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 commentaires
Walter Roberson
Walter Roberson le 27 Fév 2013
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 le 27 Fév 2013
Thanks a lot Walter.
It works.
Raúl.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by