필터 지우기
필터 지우기

xlswrite using different names

조회 수: 3 (최근 30일)
Raúl
Raúl 2013년 2월 26일
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by