Thread Subject: write matrices to an open Excel from a compiled Matlab xla/dll

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Martin

Date: 15 Sep, 2008 11:00:05

Message: 1 of 6

Hi,

I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.

So far so good.

But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
http://tinyurl.com/64wwe9)

This is not useful!

I need to return a number of matrices back to Excel for the user to do stuff with.

We have considered using xlswrite from within the compiled code.

However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.

So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?

Has anyone else come across this problem? Found a solution?
We really want to stay away from reading/writing csv files if possible.

Thanks,

Martin.

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Ilya Rozenfeld

Date: 15 Sep, 2008 14:00:18

Message: 2 of 6

In your matlab code you can do the following

% Get handle to the open Excel
h = actxGetRunningServer('Excel.Application');

% Get workbook handle
% You can select a differnt item number here or you can use
% workbook name
myBook = h.Workbooks.Item(1);

% Get sheet handle (the same comments as above apply)
mySheet = myBook.Item(1);

% Now assign matrix to a range
a = rand(5);
mySheet.Range('A1:E5').Value = a;



"Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <galf7l$8$1@fred.mathworks.com>...
> Hi,
>
> I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.
>
> So far so good.
>
> But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
> http://tinyurl.com/64wwe9)
>
> This is not useful!
>
> I need to return a number of matrices back to Excel for the user to do stuff with.
>
> We have considered using xlswrite from within the compiled code.
>
> However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.
>
> So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?
>
> Has anyone else come across this problem? Found a solution?
> We really want to stay away from reading/writing csv files if possible.
>
> Thanks,
>
> Martin.
>
>

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Martin

Date: 16 Sep, 2008 12:04:01

Message: 3 of 6

Thanks for the tips!

Just one thing that did not work for me was the line

mySheet = myBook.Item(1);

I had to change it to

mySheet = myBook.ActiveSheet;

This has really made thing easier! Thanks,

Martin.

"Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu> wrote in message <galppi$s0q$1@fred.mathworks.com>...
> In your matlab code you can do the following
>
> % Get handle to the open Excel
> h = actxGetRunningServer('Excel.Application');
>
> % Get workbook handle
> % You can select a differnt item number here or you can use
> % workbook name
> myBook = h.Workbooks.Item(1);
>
> % Get sheet handle (the same comments as above apply)
> mySheet = myBook.Item(1);
>
> % Now assign matrix to a range
> a = rand(5);
> mySheet.Range('A1:E5').Value = a;
>
>
>
> "Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <galf7l$8$1@fred.mathworks.com>...
> > Hi,
> >
> > I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.
> >
> > So far so good.
> >
> > But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
> > http://tinyurl.com/64wwe9)
> >
> > This is not useful!
> >
> > I need to return a number of matrices back to Excel for the user to do stuff with.
> >
> > We have considered using xlswrite from within the compiled code.
> >
> > However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.
> >
> > So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?
> >
> > Has anyone else come across this problem? Found a solution?
> > We really want to stay away from reading/writing csv files if possible.
> >
> > Thanks,
> >
> > Martin.
> >
> >
>

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Ilya Rozenfeld

Date: 16 Sep, 2008 12:26:02

Message: 4 of 6

Oops. It should've been

mySheet = myBook.Sheets.Item(1);

"Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <gao7bh$d4i$1@fred.mathworks.com>...
> Thanks for the tips!
>
> Just one thing that did not work for me was the line
>
> mySheet = myBook.Item(1);
>
> I had to change it to
>
> mySheet = myBook.ActiveSheet;
>
> This has really made thing easier! Thanks,
>
> Martin.
>
> "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu> wrote in message <galppi$s0q$1@fred.mathworks.com>...
> > In your matlab code you can do the following
> >
> > % Get handle to the open Excel
> > h = actxGetRunningServer('Excel.Application');
> >
> > % Get workbook handle
> > % You can select a differnt item number here or you can use
> > % workbook name
> > myBook = h.Workbooks.Item(1);
> >
> > % Get sheet handle (the same comments as above apply)
> > mySheet = myBook.Item(1);
> >
> > % Now assign matrix to a range
> > a = rand(5);
> > mySheet.Range('A1:E5').Value = a;
> >
> >
> >
> > "Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <galf7l$8$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.
> > >
> > > So far so good.
> > >
> > > But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
> > > http://tinyurl.com/64wwe9)
> > >
> > > This is not useful!
> > >
> > > I need to return a number of matrices back to Excel for the user to do stuff with.
> > >
> > > We have considered using xlswrite from within the compiled code.
> > >
> > > However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.
> > >
> > > So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?
> > >
> > > Has anyone else come across this problem? Found a solution?
> > > We really want to stay away from reading/writing csv files if possible.
> > >
> > > Thanks,
> > >
> > > Martin.
> > >
> > >
> >

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Chirackel Yoonus

Date: 22 Jan, 2009 08:24:07

Message: 5 of 6

Hi,
Ref : mySheet.Range('A1:E5').Value = a;
How we can make range variable instead of fixed range like ('A1:E5')

Thanks
Yoonus



"Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <gao7bh$d4i$1@fred.mathworks.com>...
> Thanks for the tips!
>
> Just one thing that did not work for me was the line
>
> mySheet = myBook.Item(1);
>
> I had to change it to
>
> mySheet = myBook.ActiveSheet;
>
> This has really made thing easier! Thanks,
>
> Martin.
>
> "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu> wrote in message <galppi$s0q$1@fred.mathworks.com>...
> > In your matlab code you can do the following
> >
> > % Get handle to the open Excel
> > h = actxGetRunningServer('Excel.Application');
> >
> > % Get workbook handle
> > % You can select a differnt item number here or you can use
> > % workbook name
> > myBook = h.Workbooks.Item(1);
> >
> > % Get sheet handle (the same comments as above apply)
> > mySheet = myBook.Item(1);
> >
> > % Now assign matrix to a range
> > a = rand(5);
> > mySheet.Range('A1:E5').Value = a;
> >
> >
> >
> > "Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <galf7l$8$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.
> > >
> > > So far so good.
> > >
> > > But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
> > > http://tinyurl.com/64wwe9)
> > >
> > > This is not useful!
> > >
> > > I need to return a number of matrices back to Excel for the user to do stuff with.
> > >
> > > We have considered using xlswrite from within the compiled code.
> > >
> > > However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.
> > >
> > > So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?
> > >
> > > Has anyone else come across this problem? Found a solution?
> > > We really want to stay away from reading/writing csv files if possible.
> > >
> > > Thanks,
> > >
> > > Martin.
> > >
> > >
> >

Subject: write matrices to an open Excel from a compiled Matlab xla/dll

From: Ilya Rozenfeld

Date: 22 Jan, 2009 18:24:01

Message: 6 of 6

'A1:E5' is just a string you can create any range you want e.g.

col_1 = 'A'
col_2 = D
row = 10;
myRange = [col_1 num2str(row) ':' col_2 num2str(row)]
mySheet.Range(myRange).Value = a;


"Chirackel Yoonus" <yoonus@ifmr.ac.in> wrote in message <gl9af7$q99$1@fred.mathworks.com>...
> Hi,
> Ref : mySheet.Range('A1:E5').Value = a;
> How we can make range variable instead of fixed range like ('A1:E5')
>
> Thanks
> Yoonus
>
>
>
> "Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <gao7bh$d4i$1@fred.mathworks.com>...
> > Thanks for the tips!
> >
> > Just one thing that did not work for me was the line
> >
> > mySheet = myBook.Item(1);
> >
> > I had to change it to
> >
> > mySheet = myBook.ActiveSheet;
> >
> > This has really made thing easier! Thanks,
> >
> > Martin.
> >
> > "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu> wrote in message <galppi$s0q$1@fred.mathworks.com>...
> > > In your matlab code you can do the following
> > >
> > > % Get handle to the open Excel
> > > h = actxGetRunningServer('Excel.Application');
> > >
> > > % Get workbook handle
> > > % You can select a differnt item number here or you can use
> > > % workbook name
> > > myBook = h.Workbooks.Item(1);
> > >
> > > % Get sheet handle (the same comments as above apply)
> > > mySheet = myBook.Item(1);
> > >
> > > % Now assign matrix to a range
> > > a = rand(5);
> > > mySheet.Range('A1:E5').Value = a;
> > >
> > >
> > >
> > > "Martin " <randomwraith@yahoo.CutOut.co.uk> wrote in message <galf7l$8$1@fred.mathworks.com>...
> > > > Hi,
> > > >
> > > > I have an Excel spreadsheet in which the user selects a variety of parameters. These get sent to Matlab via a command button and are fed into a Matlab function, which then goes off and does it's calculations.
> > > >
> > > > So far so good.
> > > >
> > > > But we want to compile the Matlab side of things into a dll/xla since it's not practical to have Matlab on multiple computers. Now as I understand a function within a compiled dll/xla must return a single scalar number (See the second paragraph in the section “Solution” at:
> > > > http://tinyurl.com/64wwe9)
> > > >
> > > > This is not useful!
> > > >
> > > > I need to return a number of matrices back to Excel for the user to do stuff with.
> > > >
> > > > We have considered using xlswrite from within the compiled code.
> > > >
> > > > However, it seems that xlswrite (& xlswrite1) can only write to spreadsheets through an open-write-close procedure and not to spreadsheets that are opened outside of Matlab. That's not good enough in our case. The spreadsheet is interactive and must remain so.
> > > >
> > > > So how can we send matrices of calculations back from a compiled Matlab xla/dll to and open excel spreadsheet?
> > > >
> > > > Has anyone else come across this problem? Found a solution?
> > > > We really want to stay away from reading/writing csv files if possible.
> > > >
> > > > Thanks,
> > > >
> > > > Martin.
> > > >
> > > >
> > >

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com