From: Adam Chapman on
I'm writing data to an excel sheet with "xlswrite"

I am running simulations for different modes of operation for a
vehicle, and want to write the data for each mode to a seperate sheet
in the excel file. However, I also want to give each sheet a name.

for example, If im doing a simulation for mode 3, I want to write to
Sheet 3 of the excel file and also give thet sheet the name "Mode 3"

Because im not going to necessarily be running the modes in numerical
order, I need to use
me,xlswrite(filena,earray,modenumber)

so that the sheet number is at least correct, but I really need to
name the sheets too.

Any help is greatly appreciated
From: Andy on
Adam Chapman <adamchapman1985(a)hotmail.co.uk> wrote in message <4ae8aa11-605c-4492-b97b-5510ca92e95c(a)z10g2000yqb.googlegroups.com>...
> I'm writing data to an excel sheet with "xlswrite"
>
> I am running simulations for different modes of operation for a
> vehicle, and want to write the data for each mode to a seperate sheet
> in the excel file. However, I also want to give each sheet a name.
>
> for example, If im doing a simulation for mode 3, I want to write to
> Sheet 3 of the excel file and also give thet sheet the name "Mode 3"
>
> Because im not going to necessarily be running the modes in numerical
> order, I need to use
> me,xlswrite(filena,earray,modenumber)
>
> so that the sheet number is at least correct, but I really need to
> name the sheets too.
>
> Any help is greatly appreciated

I'm not at MATLAB right now, but I thought xlswrite takes an argument for which sheet to write to? If you pass a string in that argument that has the name of a sheet that does not yet exist, it should add a new sheet with that name automatically. Have you tried this?

Also, I don't know what you mean by "so that the sheet number is correct" if you're renaming your sheets with the correct numbers anyway. Could you elaborate?
From: Adam Chapman on
On Jun 29, 8:51 pm, "Andy " <theorigam...(a)gmail.com> wrote:
> Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote in message <4ae8aa11-605c-4492-b97b-5510ca92e...(a)z10g2000yqb.googlegroups.com>...
> > I'm writing data to an excel sheet with "xlswrite"
>
> > I am running simulations for different modes of operation for a
> > vehicle, and want to write the data for each mode to a seperate sheet
> > in the excel file. However, I also want to give each sheet a name.
>
> > for example, If im doing a simulation for mode 3, I want to write to
> > Sheet 3 of the excel file and also give thet sheet the name "Mode 3"
>
> > Because im not going to necessarily be running the modes in numerical
> > order, I need to use
> > me,xlswrite(filena,earray,modenumber)
>
> > so that the sheet number is at least correct, but I really need to
> > name the sheets too.
>
> > Any help is greatly appreciated
>
> I'm not at MATLAB right now, but I thought xlswrite takes an argument for which sheet to write to?  If you pass a string in that argument that has the name of a sheet that does not yet exist, it should add a new sheet with that name automatically.  Have you tried this?
>
> Also, I don't know what you mean by "so that the sheet number is correct" if you're renaming your sheets with the correct numbers anyway.  Could you elaborate?- Hide quoted text -
>
> - Show quoted text -

It would make a new sheet if you gave it a striung yes, but let me
give an example of what im trying to do:

Say I want to sunr a simulation for "mode 5". I want that data saved
to the 5th sheet in the sxcel file, and have that sheet called "Mode
5" rather than the default "Sheet 5". I may not have written to Sheets
1-4 beforehand, so I need to define a sheet number and name for that
sheet.
From: Andy on
Adam Chapman <adamchapman1985(a)hotmail.co.uk> wrote in message <7addd750-eda3-4db8-ad70-7da59408cc91(a)r27g2000yqb.googlegroups.com>...
> On Jun 29, 8:51 pm, "Andy " <theorigam...(a)gmail.com> wrote:
> > Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote in message <4ae8aa11-605c-4492-b97b-5510ca92e...(a)z10g2000yqb.googlegroups.com>...
> > > I'm writing data to an excel sheet with "xlswrite"
> >
> > > I am running simulations for different modes of operation for a
> > > vehicle, and want to write the data for each mode to a seperate sheet
> > > in the excel file. However, I also want to give each sheet a name.
> >
> > > for example, If im doing a simulation for mode 3, I want to write to
> > > Sheet 3 of the excel file and also give thet sheet the name "Mode 3"
> >
> > > Because im not going to necessarily be running the modes in numerical
> > > order, I need to use
> > > me,xlswrite(filena,earray,modenumber)
> >
> > > so that the sheet number is at least correct, but I really need to
> > > name the sheets too.
> >
> > > Any help is greatly appreciated
> >
> > I'm not at MATLAB right now, but I thought xlswrite takes an argument for which sheet to write to?  If you pass a string in that argument that has the name of a sheet that does not yet exist, it should add a new sheet with that name automatically.  Have you tried this?
> >
> > Also, I don't know what you mean by "so that the sheet number is correct" if you're renaming your sheets with the correct numbers anyway.  Could you elaborate?- Hide quoted text -
> >
> > - Show quoted text -
>
> It would make a new sheet if you gave it a striung yes, but let me
> give an example of what im trying to do:
>
> Say I want to sunr a simulation for "mode 5". I want that data saved
> to the 5th sheet in the sxcel file, and have that sheet called "Mode
> 5" rather than the default "Sheet 5". I may not have written to Sheets
> 1-4 beforehand, so I need to define a sheet number and name for that
> sheet.

I don't think that's how the sheet numbers work. You cannot assign a number to a sheet (without, for example, creating earlier sheets). For example, the default is three sheets called Sheet 1, Sheet 2, Sheet 3. If you run mode 5 first, you cannot create a fourth sheet called Mode 5 and set its number to 5. If you did xlswrite(...,'Mode 5'), it would create sheet with number 4 and name Mode 5. If you instead did xlswrite(...,5), it would create two sheets with names Sheet 4 and Sheet 5. But then you can't change the name of Sheet 5 to Mode 5 in any direct MATLAB way, as far as I know.

If you really need this sort of control over Excel, you should look into using actxserver. But I'm not sure why you need to control both the name and number of the sheets.
From: us on
Adam Chapman <adamchapman1985(a)hotmail.co.uk> wrote in message <4ae8aa11-605c-4492-b97b-5510ca92e95c(a)z10g2000yqb.googlegroups.com>...
> I'm writing data to an excel sheet with "xlswrite"
>
> I am running simulations for different modes of operation for a
> vehicle, and want to write the data for each mode to a seperate sheet
> in the excel file. However, I also want to give each sheet a name.
>
> for example, If im doing a simulation for mode 3, I want to write to
> Sheet 3 of the excel file and also give thet sheet the name "Mode 3"
>
> Because im not going to necessarily be running the modes in numerical
> order, I need to use
> me,xlswrite(filena,earray,modenumber)
>
> so that the sheet number is at least correct, but I really need to
> name the sheets too.
>
> Any help is greatly appreciated

one of the solutions
- note: this will create a file FOO.XLS with sheets 1:NS named 'MOD 01',...,'MOD 05',...
- afterwards: use XLSWRITE to address individual sheets...

% the data
fnam=[cd,filesep,'foo.xls']; % <- your file name...
ns=5; % <- #sheets in workbook...
ts='mod %2.2d'; % <- sheet name template...
% the engine
if exist(fnam,'file') % <- !!!!!
delete(fnam); % <- !!!!!
end
ex=actxserver('Excel.Application');ex.Visible=1;
wb=ex.Workbooks.Add;
ws=wb.Sheets;
for i=ws.Count+1:ns
wb.Sheets.Add;
end
ws=wb.Sheets;
for i=1:ns
ws.Item(i).Name=sprintf(ts,i);
end
wb.SaveAs(fnam);
wb.Close;
ex.Quit;
delete(ex);
% the result
winopen(fnam);

us