How do I resize a table in excel using Matlab

12 Ansichten (letzte 30 Tage)
Erik Mele
Erik Mele am 18 Jun. 2014
Bearbeitet: Geoff Hayes am 5 Aug. 2016
Hi,
I am using Matlab to create an output sheet in excel including some graphs and a table. So far I am using the actxserver and it seems to be working quite nice for the graphs. For the Table on the other hand I seem to have a problem.
After some initial set up, like this:
Excel = actxserver('Excel.Application');
Resultfile = [pwd '\Summary plots\Summary.xlsx'];
Workbook = invoke(Excel.Workbooks,'Open',Resultfile);
set(Excel,'Visible',1);
ActSheet=Workbook.Sheets.Item(3);
ActSheet.Activate;
Workbook.ActiveSheet.Name='Data';
I use Listobjects.Add to create the table
ExpTable = Excel.ActiveSheet.Listobjects.Add;
Problem is it pops up in a "random" place and size. Then I cant seem to resize it. And reposition it.
I tried with
ExpTable.Range='$J$12:$L$13'
or
set(ExpTable.InsertRowRange.EntireRow,'Address','$J$12:$L$13')
Dont kow why it is not working. In VBA this is the code for resizing
ActiveSheet.ListObjects("Table3").Resize Range("$J$12:$L$13")
But a similar code in Matlab does not work at all
ActiveSheet.ListObjects('Table3').Resize Range('$J$12:$L$13')
Can anyone help me on this? Any help would be appreciated, thank you!
  1 Kommentar
Tino
Tino am 5 Aug. 2016
Bearbeitet: Tino am 5 Aug. 2016
Before you add the Listobject, you have to define the range:
indexSheet = 1;
range = 'A1:B3';
tablestyle = 'TableStyleMedium8';
Excel = actxserver('Excel.Application');
Sheets = Excel.ActiveWorkBook.Sheets;
ActiveSheet = get(Sheets, 'Item', indexSheet);
ActiveSheet.Activate;
Excel.ActiveSheet.Range(range).Select;
Excel.ActiveSheet.Listobjects.Add;
Excel.ActiveSheet.ListObjects.Item(1).TableStyle = tablestyle;

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by