How do I resize a table in excel using Matlab

12 ビュー (過去 30 日間)
Erik Mele
Erik Mele 2014 年 6 月 18 日
編集済み: Geoff Hayes 2016 年 8 月 5 日
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 Center および File ExchangeUse 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