Main Content

mlreportgen.ppt.Number Class

Namespace: mlreportgen.ppt

Number to include as formatted text in document

Since R2024b

Description

Use an object of the mlreportgen.ppt.Number class to convert a number to formatted text that you can include in a document.

The conversion uses the first of these format specifications that it finds:

  1. The specification in the mlreportgen.ppt.NumberFormat object in the Style property of the Number object

  2. The specification in the NumberFormat object in the Style property of the element, such as a paragraph, list, or table, that contains the Number object

  3. The default specification set by mlreportgen.ppt.setDefaultNumberFormat

If the conversion does not find a format specification, the conversion uses the maximum number of digits needed to represent the number accurately.

The mlreportgen.ppt.Number class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

numberObj = mlreportgen.ppt.Number creates an empty Number object. Use the Value property to specify the number to convert to formatted text.

numberObj = mlreportgen.ppt.Number(value) creates a Number object with the specified value.

example

Properties

expand all

Number to convert to formatted text, specified as a scalar. Complex numbers are not supported.

Attributes:

NonCopyable
true

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Style format of this number when converted to text, specified as a cell array of PPT format objects. Use an mlreportgen.ppt.NumberFormat object to specify the precision of the converted number.

Attributes:

NonCopyable
true

Data Types: cell

Parent of this object, specified as a PPT API object. A PPT API object must only have one parent.

Attributes:

SetAccess
private
NonCopyable
true

The class ignores this property.

Attributes:

SetAccess
private
NonCopyable
true

Tag for the mlreportgen.ppt.Number object, specified as a character vector or string scalar. The PPT API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specify your own tag value to help you identify where to look when an issue occurs during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Object identifier for the mlreportgen.ppt.Number object, specified as a character vector or string scalar. The PPT API generates a session-unique identifier when it creates the document element object. You can specify your own value for Id.

Attributes:

NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse all

Add formatted numbers to a presentation by using the mlreportgen.ppt.Number and mlreportgen.ppt.NumberFormat classes. Set the number formatting for the first content slide using a default value for your session and for the second content slide to a format style for that specific Number object.

Import the PPT namespace so that you do not have to use fully qualified names for the PPT API classes.

import mlreportgen.ppt.*

Set the default number formatting for the session.

setDefaultNumberFormat("%0.6f");

Create a presentation and add a title slide.

ppt = Presentation('myPresentation.pptx');
open(ppt);
slideTitle = add(ppt,"Title Slide");
replace(slideTitle,"Title","Formatted Numbers");

Create the first title and content slide. Create an mlreportgen.ppt.Paragraph object to use for the title of the slide.

slide1 = add(ppt,"Title and Content");
p1Title = Paragraph;

Create a Number object with pi and convert it to a string with the toString method.

number1Obj = Number(pi);
formattedNumber1 = toString(number1Obj);  

Append the formatted number to the paragraph.

append(p1Title,string(char(960)) + " in default format: " ...
    + formattedNumber1); % char(960) - Unicode for the pi character

Replace the title in the first title and content slide with the paragraph.

replace(slide1,"Title",p1Title);

Display the default format in the content text box.

numberFormat = getDefaultNumberFormat();
p1Content = Paragraph("Number format is : ");
p1Content.append(numberFormat);
replace(slide1,"Content",p1Content);

Create the second title and content slide. Create an mlreportgen.ppt.Paragraph object to use for the title of the slide.

slide2 = add(ppt,"Title and Content");
p2 = Paragraph;

Create a Number object with pi and convert it to a string with the toString method. Limit the decimal places of pi on this slide to two decimal points by specifying the format of the Number and overriding the default number formatting.

number2Obj = Number(pi);
number2Obj.Style = NumberFormat("%0.2f");
formattedNumber2 = toString(number2Obj);  

Append the formatted number to the paragraph.

append(p2,string(char(960)) + " in individual format: " ...
    + formattedNumber2); % char(960) - Unicode for the pi character

Replace the title in the second title and content slide with the paragraph.

replace(slide2,"Title",p2);

Display the individual format in the content text box.

p2Content = Paragraph("Number format is : ");
p2Content.append("%0.2f");
replace(slide2,"Content",p2Content);

Close and view the presentation.

close(ppt);
rptview(ppt);

Version History

Introduced in R2024b