Creating tables on MS Word

69 次查看(过去 30 天)
Jonathan Moorman
Jonathan Moorman 2021-7-8
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 个评论
Srijith Sudhagar
Srijith Sudhagar 2022-4-22
selection.MoveDown(5,1,1); %Break the table and switch to paragraph mode

请先登录,再进行评论。

回答(2 个)

Kapil Gupta
Kapil Gupta 2021-7-9

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

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by