Creating tables on MS Word

조회 수: 71 (최근 30일)
Jonathan Moorman
Jonathan Moorman 2021년 7월 8일
답변: Sean de Wolski 2022년 4월 22일
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