Report Generator DocumentPart ReportTOC Font Size

23 Ansichten (letzte 30 Tage)
Fred Schaible
Fred Schaible am 25 Mär. 2019
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);

Antworten (1)

prabhat kumar sharma
prabhat kumar sharma am 30 Jan. 2025
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!

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by