Creating tables on MS Word

60 vues (au cours des 30 derniers jours)
Jonathan Moorman
Jonathan Moorman le 8 Juil 2021
Hi all,
I am trying to create two seperate tables and add a picture to word, but the whole document is combined into one big table. What am I do wrong in my code? Thanks!
word = actxserver('Word.Application'); %start Word
word.Visible =1; %make Word Visible
document=word.Documents.Add; %create new Document
selection=word.Selection; %set Cursor
selection.Font.Name='Times New Roman'; %set Font
selection.Font.Size=18; %set Size
selection.Pagesetup.RightMargin=50; %set right Margin
selection.Pagesetup.LeftMargin=50; %set left Margin
selection.Pagesetup.TopMargin=50; %set top Margin
selection.Pagesetup.BottomMargin=50; %set bottom Margin
selection.Paragraphs.LineUnitAfter=0.01; %sets the amount of spacing
selection.Font.Size=12;
%Creating Model input Table
word.Selection.Font.Bold = 1;
word.Selection.TypeText('Model Inputs');
word.Selection.Font.Bold = 0;
word.ActiveDocument.Tables.Add(word.Selection.Range,4,2);
word.Selection.TypeText('Equation 1');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('y = mx+b');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('Equation 2');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('y = mx+b');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('Crack Scatter Factor');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('1');
tableObj = word.ActiveDocument.Tables.Item(1);
word.Selection.MoveRight(12,1,0);
word.Selection.TypeParagraph
%Creating Results Table
word.Selection.Font.Bold = 1;
word.Selection.TypeText('90th Percentiles');
word.Selection.MoveRight(12,1,0);
word.Selection.Font.Bold = 0;
word.Selection.TypeText('a50 @Cal');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText(num2str('50'));
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('a50 @+6dB');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('59');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('a50 @+12dB');
word.Selection.MoveRight(12,1,0);
word.Selection.TypeText('33');
word.Selection.TypeParagraph
tableObj.Borders.Enable = 1;
%Add figures
selection.InlineShapes.AddPicture([pwd '/Figure1.jpg'],0,1);
selection.TypeParagraph;
  1 commentaire
Srijith Sudhagar
Srijith Sudhagar le 22 Avr 2022
selection.MoveDown(5,1,1); %Break the table and switch to paragraph mode

Connectez-vous pour commenter.

Réponses (2)

Kapil Gupta
Kapil Gupta le 9 Juil 2021

Sean de Wolski
Sean de Wolski le 22 Avr 2022
This is exactly what the MATLAB Report Generator does really well. Look at the sections on tables and images, here:

Catégories

En savoir plus sur Tables 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!

Translated by