Creating tables on MS Word
64 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Srijith Sudhagar
el 22 de Abr. de 2022
selection.MoveDown(5,1,1); %Break the table and switch to paragraph mode
Respuestas (2)
Kapil Gupta
el 9 de Jul. de 2021
I assume you want to create tables in MS Word. The following MATLAB Answers links have similar queries, you can check these out:
0 comentarios
Sean de Wolski
el 22 de Abr. de 2022
This is exactly what the MATLAB Report Generator does really well. Look at the sections on tables and images, here:
0 comentarios
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!