Main Content

Display Presentation Generation Messages

Presentation Generation Messages

The PPT API can display messages when you generate a PowerPoint® presentation. The messages are triggered every time a presentation element is created or appended during presentation generation.

You can define additional messages to display while a presentation generates. The PPT API provides these classes for defining messages:

  • ProgressMessage

  • DebugMessage

  • WarningMessage

  • ErrorMessage

The PPT API provides additional classes for handling presentation message dispatching and display. It uses MATLAB® events and listeners to dispatch messages. A message is dispatched based on event data for a specified PPT object. For an introduction to events and listeners, see Event and Listener Concepts.

Note

When you create a message dispatcher, the PPT API keeps the dispatcher until the end of the current MATLAB session. To avoid duplicate reporting of message objects during a MATLAB session, delete message event listeners.

Display PPT Default Messages

This example shows how to display the default PPT debug messages. Use a similar approach for displaying other kinds of PPT presentation messages.

  1. Create a message dispatcher, using the MessageDispatcher.getTheDispatcher method. Use the same dispatcher for all messages.

    dispatcher = MessageDispatcher.getTheDispatcher;
    
  2. To display debug messages, use the MessageDispatcher.Filter property.

    dispatcher.Filter.DebugMessagesPass = true;
    
  3. Add a listener using the MATLAB addlistener function. Specify the dispatcher object, the source and event data, and a disp function that specifies the event data and format for the message.

    l = addlistener(dispatcher,'Message', ...
          @(src, evtdata) disp(evtdata.Message.formatAsText));
    
  4. Add code that deletes the listener after the code that generates the presentation.

    delete(l);
    

This presentation displays debug messages.

import mlreportgen.ppt.*;

dispatcher = MessageDispatcher.getTheDispatcher;
dispatcher.Filter.DebugMessagesPass = true;

l = addlistener(dispatcher,'Message', ...
      @(src, evtdata) disp(evtdata.Message.formatAsText));

slides = Presentation('myMessagePresentation');
titleSlide = add(slides,'Title and Content');

p = Paragraph('Hello World:');
p.Style = {Bold(true)};
t = Text('  How are you?');
t.Bold = false;
append(p,t);


add(titleSlide,'Content',p);

close(slides);
     
delete(l);

Create and Display a Progress Message

This example shows how to create and dispatch a progress message. You can use a similar approach for other kinds of messages, such as warnings.

  1. Create a message dispatcher.

    dispatcher = MessageDispatcher.getTheDispatcher;
    
  2. Add a listener using the MATLAB addlistener function.

    l = addlistener(dispatcher,'Message', ...
          @(src, evtdata) disp(evtdata.Message.formatAsText));
    
  3. Dispatch the message, using the Message.dispatch method. Specify the dispatcher object and the message to dispatch. Here the message is a debug message called firstSlide, and the Presentation object slides is the source of the message.

    dispatch(dispatcher,ProgressMessage('firstSlide',slides));
    
  4. Add code that deletes the listener after the code that generates the presentation.

    delete(l);
    

This presentation uses this progress message.

import mlreportgen.ppt.*;
pre = Presentation('myPresentation.pptx');

dispatcher = MessageDispatcher.getTheDispatcher;
l = addlistener(dispatcher,'Message', ...
      @(src, evtdata) disp(evtdata.Message.formatAsText));


dispatch(dispatcher,ProgressMessage('starting presentation',pre));
open(pre);

titleText = Text('This is a Title');
titleText.Style = {Bold};

replace(pre,'Title',titleText);

close(pre);

delete(l);

See Also

Functions

Classes