MATLAB report generator - Microsoft word header/footer 'Link to Previous' Section
40 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to create a Microsoft word report . The first few pages are written directly from another program. The next pages are written from MATLAB based on word template already saved. I need the page headers and footers continued from the previous section. I was unable to find something which is similar to 'Link to Previous' as in word. Can someone help?
0 个评论
回答(1 个)
Gayathri
2024-11-7,4:47
For appending data to an existing word, we can use the MATLAB's ActiveX interface. This will automatically get continued with the existing headers and footers.
Start by creating a Word ActiveX server and opening your template document. Please find the below code for using the Word ActiveX interface.
% Start an ActiveX session with Word
wordApp = actxserver('Word.Application');
wordApp.Visible = true; % Make Word visible for debugging
% Open the existing Word document
docPath = 'path\new1.docx';
doc = wordApp.Documents.Open(docPath);
% Move to the end of the document
selection = wordApp.Selection;
wdStory = 6; % The numeric value for wdStory
selection.EndKey(wdStory);
% Insert a section break (next page)
wdSectionBreakNextPage = 2; % The numeric value for wdSectionBreakNextPage
selection.InsertBreak(wdSectionBreakNextPage);
% Add new content after the section break
selection.TypeText('This is a new paragraph added after a section break.');
selection.TypeParagraph; % Add a new paragraph break
% Add a table (example with 2 rows and 2 columns)
selection.Tables.Add(selection.Range, 2, 2);
table = selection.Tables.Item(1);
table.Cell(1, 1).Range.Text = 'Header 1';
table.Cell(1, 2).Range.Text = 'Header 2';
table.Cell(2, 1).Range.Text = 'Row 1 Col 1';
table.Cell(2, 2).Range.Text = 'Row 1 Col 2';
% Save and close the document
doc.Save();
doc.Close(false);
wordApp.Quit;
For more information on “actxserver”, please refer to the following link.
Hope you find this information helpful.
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!