From: rams on
Hi,
My program reads all excel files in current directory and writes data in different excel files to a single excel file with different sheets. I am wondering is there any way to name sheets in excel file while i try to write the data...my code is

files=dir('*.xls');
t=1;
for k = 1:numel(files)
A = xlsread(files(k).name);
xlswrite('All_stations',A,t);
t=t+1;
end
Thank you!
From: us on
rams <lramsb4u(a)gmail.com> wrote in message <218694178.62278.1278105992006.JavaMail.root(a)gallium.mathforum.org>...
> Hi,
> My program reads all excel files in current directory and writes data in different excel files to a single excel file with different sheets. I am wondering is there any way to name sheets in excel file while i try to write the data...my code is
>
> files=dir('*.xls');
> t=1;
> for k = 1:numel(files)
> A = xlsread(files(k).name);
> xlswrite('All_stations',A,t);
> t=t+1;
> end
> Thank you!

a hint:
- of course, just peruse

help xlswrite;

us
From: ImageAnalyst on
Yes, but you have to pass it a character string as the third argument,
not an integer. You can use sprintf() to build up a string from t if
you want.

By the way, your code is a very slow and inefficient way of doing it
since each time you call xlswrite, it has to launch Excel, poke in the
data, then shut down Excel. Take a look at xlswrite1 in the File
Exchange. You just open Excel once, then call xlswrite1 as many times
as you want, then you close Excel - this way is much, much faster.