Code covered by the BSD License  

Highlights from
wordreport

4.33333

4.3 | 9 ratings Rate this file 54 Downloads (last 30 days) File Size: 34.2 KB File ID: #17953

wordreport

by

 

10 Dec 2007 (Updated )

A Word report generator (ActiveX-based) in an object-oriented way

| Watch this File

File Information
Description

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 !

Acknowledgements

Write To Word From Matlab inspired this file.

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Works only on Windows Platforms with at least Office 2000 installed (might also work with Office 97, to investigate...)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
27 Feb 2013 James

Ran, Deborah and others, I had this problem but it seemed to go away when using absolute file paths to the Word document. I used http://www.mathworks.co.uk/matlabcentral/fileexchange/29768-absolutepath/content/absolutepath/src/absolutepath.m to get the absolute paths.

24 Feb 2012 Deborah

I get the same error as Ran. Is the author still supporting this??

10 Jan 2012 RubenMath

Has anyone tested the GoTo method ?

For some reason, when I try to goto an exsiting bookmark, I get:

Invoke Error, Dispatch Exception:

07 May 2011 Ran

doen't work with my office 10
this is the error i receive
Warning: Resetting generic name for heading styles to default 'Heading '
> In wordreport_demo at 47
??? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: ???? ??? ????? ???? ????.
Help File: C:\Program Files\Microsoft Office\Office10\1037\wdmain10.chm
Help Context ID: 62e2

Error in ==> wordreport>AddText at 187
hdlActiveX.Selection.Style = currentStyle;

Error in ==> wordreport_demo at 51
wr.addtext(textString, [0 2]); % two line breaks after text

05 Jan 2010 K E

Fabulous, thanks. How would I apply Word's built-in table formatting, such as Selection.Tables(1).Style = "Light Shading" ?

08 Aug 2008 Romain Gar

Good work, i have just one question : I already made a Simulink Report Generator. But my work is to put my Simulink Report into an old existing Word Document, which contains some informations not coming from simulink model. I want to put into this WordDocument my Report in certain section.
Can you help me?

08 Jun 2008 Moises enrique

Excellent work!!! Two questions 1) Can an example modified to include a proper report format with title page and diffent color and size fonts. 2) The the processing be done in the back ground without openning anything? Thanks a lot.

06 Apr 2008 Gernot Druml

Thanks, it makes my life realy easier.
Especially the functionality to insert on an selected place of word helps me in the daily work

13 Dec 2007 Laurent Vaylet

Riccardo,

1) The plugins system you mention would be ideal to ensure maximal power and modularity. This kind of contribution could greatly benefit from such an architecture. It's also true that i have a few ideas on how to rewrite the code to accept and automatically detect subfunctions. However, it's a time-consuming task so i can't promise i'm going to implement these features :-( Right now, i prefer to concentrate on a full demo of all current possibilities.

2) I could certainly set up this kind of structure if i was hired by the Mathworks but unfortunately it is not the case :-) I already have a full-time job and a rest-of-the-time girlfriend that both imply not-too-much-remaining-time for a thread about a subject as complex as ActiveX.

WORDREPORT and all of its contents are "open-source" so feel free (as in free speech and free beer) to update/expand/modify it if you realize i'm no longer maintaining it. As you said, it's just the beginning. There are endless possibilities to what you can do with ActiveX !

Thanks again for your suggestions and see you soon for a full demo (and maybe more...).

Laurent

13 Dec 2007 as you point o Meldolesi

Laurent,

Good job.

It is simple and works well.

I have a couple of suggestions:

1) as you point out this tool is destined to grow. A limitation to the growt is the fact that if WORDREPORT is all contained into a simgle file it would require editing to merge different "subfunctions" posted by different people.
It would be good for people to be able to post separate "subfunctions" on to the mathworks website and for people to be able to download them and plug them in by copying them into a directory, without editing WORDREPORT. This means that the main function WORDREPORT would have to have a function which updates the links to the external subfunctions.

I can see this working better.

2) Have you considered starting a forum on the Mathworks website as a dpository for the plugin and general discussions on how to use activeX?

Riccardo

12 Dec 2007 Laurent Vaylet

Dimitri,

Thanks for your congratulations and constructive remarks. To answer them:

0 - I'm currently working on externalizing a full demo including Simulink/Stateflow screenshots. Hope to release it by the end of the week, depending on my workload.

1 - I'm afraid I won't be able to speed things up :-( Execution speed must be limited by the ActiveX technology itself. Someone has any idea on the subject ?

2 - Actually, Word is opened once at the beginning then hidden during the process of adding content. However, it may be possible to play with the Visible property and the Trace method (in CreateDoc) to completely hide the process and prevent user from taking control.

3 - To override this 'append-by-default' behavior, you can check for file existence and then decide whether to keep the file or not. You can also use the GOTO method to jump to a specified item of the document (table, heading, figure, line, section, ...).

4 - I agree, there's plenty of room for improvement on this part :-)

5 - Default settings for line breaks is [0 1] (one after and none before) so you can get rif of this argument most of the time. However, your linebreak method is not a bad idea. To investigate too, maybe in the next version !

See you later for the full demo pack,

Laurent

12 Dec 2007 Dimitri Shvorob

Great job! This is definitely more convenient than the predecessor, Andreas Karlsson's 'wordtext'. I wonder if there are functional improvements as well - could the author expand the demo, setting it up as a proper m-file?

Here are a few wrinkles that do not detract from Laurent's accomplishment.

1. The process is relatively slow: the demo took 15 seconds to run.

2. Word is opened, closed and re-opened; could the document creation proceed 'behind -the-scenes'?

3. 'Append-by-default' behavior: if the target document exists, it will be added to.

4. Table output is very cumbersome and cries out for improvement.

5. Surely it's possible to dispense with the '[0, 0]'s, '[0 1]'s and '[1 1]'s by introducing a line-break method?

12 Dec 2007 CAE support

Good job! As said a friend close to me: "c'est guenial!".

Updates
11 Dec 2007

Minor update to sample code in Description field

26 Jun 2009

Updated license.txt to BSD

06 Jul 2009

Updated BSD Organization to The MathWorks, Inc

Contact us