How do I resize a table in excel using Matlab

12 次查看(过去 30 天)
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 个评论
Tino
Tino 2016-8-5
编辑:Tino 2016-8-5
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;

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by