How do I resize a table in excel using Matlab
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Tino
le 5 Août 2016
Modifié(e) : Tino
le 5 Août 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;
Réponses (0)
Voir également
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!