MATLAB Examples

Object-Oriented Report

This example illustrates an object-oriented approach to creating a report generator based on the DOM API. It uses the DOM API to create pair of MATLAB classes, MagicSquareReport and MagicSquareChapter, that generate a PDF, Microsoft Word, or HTML report on a set of magic squares.

IMPORTANT! Click the Open Script button on this page to use this example. This will download the example and its supporting files to your home directory.

Contents

Generate a Report

1. Open this example if it is not already open.

2. Generate an HTML, Word, or PDF report on four magic squares as follows:

  • Click to generate an HTML report:

rptmagicoo([10,20,40,75],'html',true)

  • Click to generate a Word report:

rptmagicoo([10,20,40,75],'docx',true)

  • Click to generate a PDF report:

rptmagicoo([10,20,40,75],'pdf',true)

Edit the Example's Word Templates

This example uses two Microsoft Word templates to generate a Word report:

  • A main template that defines the format and fixed content of the reports title, table-of-contents, and introductory chapter.
  • A chapter template that defines the layout and fixed content of the chapters containing magic squares. The magic square chapter template is stored in the Quick Parts gallery of the main template.

You can edit these templates to change the appearance of a generated report:

1. Open this example (if it is not already open).

2. Click winopen('magic_squares_docx.dotx') to open the template in Word

3. Edit the template(s) in Word.

4. Save the template(s).

5. Click rptmagicoo([10,20,40,75],'docx',true) to generate a report based on the modified template(s).

Edit the Example's HTML Templates

This example uses two HTML templates to generate an HTML report:

  • A main template that defines the format and fixed content of the reports title, table-of-contents, and introductory chapter.
  • A chapter template that defines the layout and fixed content of the chapters containing magic squares. The magic square chapter template resides in the main template's document part template library.

To edit the HTML templates:

1. Click unzipTemplate('magic_squares_html.htmtx') to unzip the template.

2. Click edit('magic_squares_html/root.html') to open the template root document in the MATLAB editor.

3. Click edit('magic_squares_html/docpart_templates.html') to open the document part templates library document in the MATLAB editor.

4. Click edit('magic_squares_html/stylesheets/root.css') to open the report style sheet in the MATLAB editor.

4. Edit the template's files in the MATLAB editor.

5. Save the templates files.

6. Click zipTemplate('magic_squares_html.htmtx') to rezip the template.

7. Click rptmagic([10,20,40,75],'html',true) to generate a report based on the modified template.

Edit the Example's PDF Templates

This example uses two PDF templates to generate a PDF report:

  • A main template that defines the format and fixed content of the reports title, table-of-contents, and introductory chapter.
  • A chapter template that defines the layout and fixed content of the chapters containing magic squares. The magic square chapter template resides in the main template's document part template library.

To edit the PDF templates:

1. Click unzipTemplate('magic_squares_pdf.pdftx') to unzip the template.

2. Click edit('magic_squares_pdf/root.html') to open the template root document in the MATLAB editor.

3. Click edit('magic_squares_pdf/docpart_templates.html') to open the report style sheet in the MATLAB editor.

4. Click edit('magic_squares_pdf/stylesheets/root.css') to open the document part templates library document in the MATLAB editor.

5. Edit the template files in the MATLAB editor.

6. Save the files.

7. Click zipTemplate('magic_squares_pdf.pdftx') to rezip the template.

8. Click rptmagicoo([10,20,40,75],'pdf',true) to generate a report based on the modified template.

Edit the Example Code

1. Open this example if it is not already open.

2. Click edit('rptmagicoo.m') to open rptmagicoo.m in the MATLAB editor.

3. Edit rptmagicoo.m.

4. Save rptmagicoo.m.

6. Rerun rptmagicoo.m to see the results of your changes.