image thumbnail

wordreport

version 1.2.0.0 (34.2 KB) by Laurent Vaylet
A Word report generator (ActiveX-based) in an object-oriented way

5.4K Downloads

Updated 06 Jul 2009

View License

WORDREPORT creates or opens an existing Microsoft Office Word report and provides helper functions to add some content: text, figures, Simulink models, Stateflow charts and much more. It also helps in adding or updating the table of contents, in setting page numbering or in finding text. Actually, it is possible to mimic almost everything you can do manually. Just record a macro in Word and analyze the generated VBA code to find out how to use the ActiveX technology.

Example: create a new document called 'Foo.doc' and add some content (headings, figures, page breaks, page numbers, table of contents)

reportFilename = fullfile(pwd,'foo.doc');
wr = wordreport(reportFilename);
%---
wr.setstyle('Heading 1');
wr.addtext('TOC', [1 1]); line break before and after text
wr.createtoc(1, 3);
wr.addpagebreak();
%---
wr.setstyle('Heading 1');
wr.addtext('MATLAB data', [1 1]); line break before and after text
%---
wr.setstyle('Heading 2');
wr.addtext('Sample table', [0 1]); line break after text
dataCell = { ...
'Test 1', num2str(0.3) , 'OK'; ...
'Test 2', num2str(1.8) , 'KO'};
[nbRows, nbCols] = size(dataCell);
wr.addtable(nbRows, nbCols, dataCell, [1 1]); line break before table
%---
wr.setstyle('Heading 2');
wr.addtext('Sample figure', [0 1]); line break after text
figure; plot(1:10);
title('Figure 1'); xlabel('Temps [s]'); ylabel('Amplitude [A]');
wr.setstyle('Normal');
wr.addfigure();
%---
wr.addpagenumbers('wdAlignPageNumberRight');
wr.updatetoc();
%---
wr.close();
%---
open(reportFilename);

Do not hesitate to ask for more help and more advanced examples, especially when dealing with screenshots of Simulink models and Stateflow charts. I'll be happy to be of any assistance !

Cite As

Laurent Vaylet (2021). wordreport (https://www.mathworks.com/matlabcentral/fileexchange/17953-wordreport), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: WriteToWordFromMatlab

Community Treasure Hunt

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

Start Hunting!