From: Adam Chapman on
I've managed to select a range of cells in my workbook and I want to
paste an array into those cells.

Select(Range(ActSheet,'A1:C100'));

I then tried to use
ActCell = get(Spreadsheet1,'ActiveCell');
set(ActCell,'Value',data);

but it didn't work. I assumed the active cell property would cover the
whole range selected, but it doesn't appear so.

If I try
ActRange = get(Spreadsheet1,'Range');
I recieve an error:


??? Invoke Error: Incorrect number of arguments

Error in ==> torquecurveinput8>labelupdate at 264
ActRange = get(Spreadsheet1,'Range');


How can I successfully paste an array of data without having to run
through each individual cell in the range with nested for loops?
From: Adam Chapman on
On Jul 21, 8:57 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
wrote:
> I've managed to select a range of cells in my workbook and I want to
> paste an array into those cells.
>
> Select(Range(ActSheet,'A1:C100'));
>
> I then tried to use
> ActCell = get(Spreadsheet1,'ActiveCell');
> set(ActCell,'Value',data);
>
> but it didn't work. I assumed the active cell property would cover the
> whole range selected, but it doesn't appear so.
>
> If I try
> ActRange = get(Spreadsheet1,'Range');
> I recieve an error:
>
> ??? Invoke Error: Incorrect number of arguments
>
> Error in ==> torquecurveinput8>labelupdate at 264
>     ActRange = get(Spreadsheet1,'Range');
>
> How can I successfully paste an array of data without having to run
> through each individual cell in the range with nested for loops?

Lines 21-23 of the example at
http://www.mathworks.com/support/solutions/en/data/1-17PWC/index.html?solution=1-17PWC
work, but not on a workbook inside a GUI.

When I use the same method in my GUI, the same example array "A" does
not appear on the spreadsheet.
If A has a single value, that value will be pasted over the whole
range specified, but if numel(A)>1, nothing appears
From: Adam Chapman on
On Jul 21, 9:15 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
wrote:
> On Jul 21, 8:57 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
> wrote:
>
>
>
>
>
> > I've managed to select a range of cells in my workbook and I want to
> > paste an array into those cells.
>
> > Select(Range(ActSheet,'A1:C100'));
>
> > I then tried to use
> > ActCell = get(Spreadsheet1,'ActiveCell');
> > set(ActCell,'Value',data);
>
> > but it didn't work. I assumed the active cell property would cover the
> > whole range selected, but it doesn't appear so.
>
> > If I try
> > ActRange = get(Spreadsheet1,'Range');
> > I recieve an error:
>
> > ??? Invoke Error: Incorrect number of arguments
>
> > Error in ==> torquecurveinput8>labelupdate at 264
> >     ActRange = get(Spreadsheet1,'Range');
>
> > How can I successfully paste an array of data without having to run
> > through each individual cell in the range with nested for loops?
>
> Lines 21-23 of the example athttp://www.mathworks.com/support/solutions/en/data/1-17PWC/index.html...
> work, but not on a workbook inside a GUI.
>
> When I use the same method in my GUI, the same example array "A" does
> not appear on the spreadsheet.
> If A has a single value, that value will be pasted over the whole
> range specified, but if numel(A)>1, nothing appears- Hide quoted text -
>
> - Show quoted text -


This is my method:
%make handle to current sheet
Activesheet = Spreadsheet1.Activesheet;
% Put a MATLAB array into Excel
A = [1 2; 3 4];
%select region
ActivesheetRange = get(Activesheet,'Range','A1:B2');
%give value to handle
set(ActivesheetRange, 'Value', A);

Matlab does not complain about the above at all, although the values
don't actually appear in the spreadsheet. UNLESS I change "A" so that
it has a single value (i.e. numel(A)=1)


Now If I try to see if the values went in but just aren't visible,
with:

Range = get(Activesheet, 'Range', 'A1:B2')
B = Range.value

I get:
B =

[NaN] [NaN]
[NaN] [NaN]

From: Adam Chapman on
On Jul 21, 9:41 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
wrote:
> On Jul 21, 9:15 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
> wrote:
>
>
>
>
>
> > On Jul 21, 8:57 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk>
> > wrote:
>
> > > I've managed to select a range of cells in my workbook and I want to
> > > paste an array into those cells.
>
> > > Select(Range(ActSheet,'A1:C100'));
>
> > > I then tried to use
> > > ActCell = get(Spreadsheet1,'ActiveCell');
> > > set(ActCell,'Value',data);
>
> > > but it didn't work. I assumed the active cell property would cover the
> > > whole range selected, but it doesn't appear so.
>
> > > If I try
> > > ActRange = get(Spreadsheet1,'Range');
> > > I recieve an error:
>
> > > ??? Invoke Error: Incorrect number of arguments
>
> > > Error in ==> torquecurveinput8>labelupdate at 264
> > >     ActRange = get(Spreadsheet1,'Range');
>
> > > How can I successfully paste an array of data without having to run
> > > through each individual cell in the range with nested for loops?
>
> > Lines 21-23 of the example athttp://www.mathworks.com/support/solutions/en/data/1-17PWC/index.html...
> > work, but not on a workbook inside a GUI.
>
> > When I use the same method in my GUI, the same example array "A" does
> > not appear on the spreadsheet.
> > If A has a single value, that value will be pasted over the whole
> > range specified, but if numel(A)>1, nothing appears- Hide quoted text -
>
> > - Show quoted text -
>
> This is my method:
> %make handle to current sheet
> Activesheet = Spreadsheet1.Activesheet;
> % Put a MATLAB array into Excel
> A = [1 2; 3 4];
> %select region
> ActivesheetRange = get(Activesheet,'Range','A1:B2');
> %give value to handle
> set(ActivesheetRange, 'Value', A);
>
> Matlab does not complain about the above at all, although the values
> don't actually appear in the spreadsheet. UNLESS I change "A" so that
> it has a single value (i.e. numel(A)=1)
>
> Now If I try to see if the values went in but just aren't visible,
> with:
>
> Range = get(Activesheet, 'Range', 'A1:B2')
> B = Range.value
>
> I get:
> B =
>
>     [NaN]    [NaN]
>     [NaN]    [NaN]- Hide quoted text -
>
> - Show quoted text -

Ah I've found it.

For anyone looking this up, "A" needs to be a cell array, i.e.
A={1,2;3,4};
instead of the standard
A=[1,2;3,4];

:)