From: Jean-Philip Dumont on
Hi,

I'm trying to use xlswrite2007.m of Travis. Its a modified and faster version of xlswrite.
http://www.mathworks.com/matlabcentral/fileexchange/?term=tag:%22excel%22

What I understand is that you have to run this code to create the file if it doesn't exist (this code is in a function i created seperatly : [ExcelWorkbook Excel] = xlswrite2007_D(file) ):

Excel = actxserver('Excel.Application');
File = sprintf(...
'C:\\Documents and Settings\\Jean-Philip\\Mes documents\\HEC\\Maîtrise\\Projet supervisé\\Codes\\%s.xls'...
,file(:));
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File)
ExcelWorkbook.Close(false);
end
ExcelWorkbook = Excel.workbooks.Open(File);

I use sprintf for the File name because I'm running this into a loop (creating several excel files in the loop.

Once the file is created, I run the whole code for all my indexes. In the end, I run this code to save and close the file created (this code is in this function : xlswrite2007_F(ExcelWorkbook, Excel) ) :

ExcelWorkbook.Save
ExcelWorkbook.Close(false) % Close Excel workbook.
Excel.Quit;
delete(Excel);

Here is the loop I use to import datas into several excel files :

for h=1:length(Snames)
[ExcelWorkbook, Excel] = xlswrite2007_D(sprintf('%s-%s',...
ExcelName{1,:},Snames{1,h}));
for i=1:length(Tnames)
for j=1:length(Dnames)
names = fieldnames(Y.(Snames{1,1}).(Tnames{1,1}).(Dnames{1,j})...
.(Cnames{1,1}));
for k=1:length(Cnames)
for l=1:length(names)
xlswrite2007(sprintf('%s-%s',ExcelName{1,:},Snames{1,h}),Y...
.(Snames{1,h}).(Tnames{1,i}).(Dnames{1,j}).(Cnames{1,k})...
.(names{l,1}),sprintf('Y.%s.%c.%d.%d.%c;',Snames1{1,h}...
,Tnames{1,i},Dnumbers(1,j),Type(k,1),names{l,1}));
end
end
end
end
xlswrite2007_F(ExcelWorkbook, Excel);
end

When I run this code just like that, everything works perfectly. BUT, this code is itself into a function which I called extract. This function doesn't have any output because basically the only thing that this function does is importing data into excel files. When I run this function (extract) it only creates the excel file but never saves the data imported into the excel files so I end up with empty excel files. Basically, my code works if i run it inside the function but doesnt when I run the actual function extract

It is obvious that i'm missing a detail somwhere but i'm just unable to find what.

Can someone help me on that?

Thank you very much!

Jean-Philip
From: ImageAnalyst on
Jean-Philip:
Have you used the debugger to see if it's actually stepping into your
for loops? If it didn't that would explain why you're getting empty
workbooks.
From: Jean-Philip Dumont on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <4a630c71-fbdc-438e-bc58-8c5ca865e7ec(a)v41g2000yqv.googlegroups.com>...
> Jean-Philip:
> Have you used the debugger to see if it's actually stepping into your
> for loops? If it didn't that would explain why you're getting empty
> workbooks.

I did and I saw that the fonction is working as it should. Basically, when I run the function extract, it does the exact same thing if I was directly running the loop.

The difference with running the loop directly or in an external function is that running the external function only gives you the output requested and doesn't save the datas calculated in order to get this output.

What I think is I have to put an output or something like that but I just can't figure it out. Its as if a data wasn't saved while running the function that I need in order to have my datas saved and exported into the excel file.
From: ImageAnalyst on
Why don't you give the full listings of your xlswrite2007_D(file)
function and your xlswrite2007_F(ExcelWorkbook, Excel) function?