xlswrite using different names
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
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
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');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!