MATLAB report generator - Microsoft word header/footer 'Link to Previous' Section

4 ビュー (過去 30 日間)
HORMIS
HORMIS 2024 年 11 月 6 日
編集済み: Gayathri 2024 年 11 月 11 日
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?

回答 (1 件)

Gayathri
Gayathri 2024 年 11 月 7 日
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 件のコメント
HORMIS
HORMIS 2024 年 11 月 11 日
I have solved the issue by updating my template, removing the section breaks.
Gayathri
Gayathri 2024 年 11 月 11 日
編集済み: Gayathri 2024 年 11 月 11 日
@HORMIS,Thank you for letting know the changes that led to resolvement of the issue.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by