Report Generator DocumentPart ReportTOC Font Size

조회 수: 25 (최근 30일)
Fred Schaible
Fred Schaible 2019년 3월 25일
답변: prabhat kumar sharma 2025년 1월 30일
How do I change the font size at the end of the TOC? It is extremely large at 1638 using the following code:
import mlreportgen.dom.*;
doc = Document('testing','docx');
open(doc);
append(doc,DocumentPart(doc,'ReportTOC'));
close(doc);
rptview(doc.OutputPath);
I checked the template and the table of contents there does not have this font size at the end.
Reproduced the same issue using the documentation code found below and switching the document type from pdf to docx.
import mlreportgen.dom.*;
d = Document('MyReport','docx');
append(d,'My Report');
append(d,DocumentPart(d,'ReportTOC'));
append(d,Heading1('Chapter 1'));
append(d,Heading2('Section 1'));
close(d);
rptview(d.OutputPath);

답변 (1개)

prabhat kumar sharma
prabhat kumar sharma 2025년 1월 30일
Hello Fred,
The issue you're encountering with an unexpectedly large font size at the end of the Table of Contents (TOC) in a Word document generated using MATLAB's mlreportgen.dom package might be due to the default styles applied to the TOC or the document itself. To resolve this, you can explicitly set the font size for the TOC entries or modify the document's style template.
Here's how you can adjust the font size for the TOC:
Step-by-Step Solution
  1. Create a Custom Template: Modify the default Word template to adjust the styles for the TOC. This involves creating a custom Word template with the desired styles and using it in your report.
  2. Modify TOC Styles Programmatically: If you want to adjust the TOC styles directly in your script without modifying the template, you can apply styles to the TOC entries using the mlreportgen.dom package.
Example Code to Modify TOC Font Size
Here's how you can adjust the font size of the TOC entries programmatically:
import mlreportgen.dom.*;
% Create a document
doc = Document('MyReport', 'docx');
% Open the document
open(doc);
% Add a title to the document
append(doc, 'My Report');
% Create a TOC with a specific style
tocPart = DocumentPart(doc, 'ReportTOC');
% Create a style for TOC entries
tocStyle = DOCXPageHeaderFooter('default');
tocStyle.FontSize = '12pt'; % Set the desired font size
% Apply the style to the TOC
append(tocPart, tocStyle);
% Append the TOC to the document
append(doc, tocPart);
% Add some content to the document
append(doc, Heading1('Chapter 1'));
append(doc, Heading2('Section 1'));
% Close and view the document
close(doc);
rptview(doc.OutputPath);
I hope it helps!

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by