Edit

Share via


PowerPoint.TableCell class

Represents a table.

Extends

Remarks

[ API set: PowerPointApi 1.8 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/add-modify-tables.yaml

// Updates a table's values.
await PowerPoint.run(async (context) => {
  const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;

  // Add a table (which is a type of Shape).
  const shape = shapes.addTable(4, 3);
  let table = shape.getTable();
  table.load();
  await context.sync();

  // Update values in the table.
  for (let rowIndex = 0; rowIndex < table.rowCount; rowIndex++) {
    for (let columnIndex = 0; columnIndex < table.columnCount; columnIndex++) {
      const cell = table.getCellOrNullObject(rowIndex, columnIndex);
      cell.text = generateRandomString();
    }
  }

  await context.sync();
});

Properties

borders

Gets the collection of borders for the table cell.

columnCount

Gets the number of table columns this cell spans across. Will be greater than or equal to 1.

columnIndex

Gets the zero-based column index of the cell within the table.

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

fill

Gets the fill color of the table cell.

font

Gets the font of the table cell.

horizontalAlignment

Specifies the horizontal alignment of the text in the table cell.

indentLevel

Specifies the indent level of the text in the table cell.

margins

Gets the set of margins in the table cell.

rowCount

Gets the number of table rows this cell spans across. Will be greater than or equal to 1.

rowIndex

Gets the zero-based row index of the cell within the table.

text

Specifies the text content of the table cell.

textRuns

Specifies the contents of the table cell as an array of objects. Each TextRun object represents a sequence of one or more characters that share the same font attributes.

verticalAlignment

Specifies the vertical alignment of the text in the table cell.

Methods

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

resize(rowCount, columnCount)

Resizes the table cell to span across a specified number of rows and columns. If rowCount or columnCount are greater than 1, the cell will become a merged area. If the cell is already a merged area and rowCount and columnCount are set to 1, the cell will no longer be a merged area.

split(rowCount, columnCount)

Splits the cell into the specified number of rows and columns.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original PowerPoint.TableCell object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.TableCellData) that contains shallow copies of any loaded child properties from the original object.

Property Details

borders

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the collection of borders for the table cell.

readonly borders: PowerPoint.Borders;

Property Value

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

columnCount

Gets the number of table columns this cell spans across. Will be greater than or equal to 1.

readonly columnCount: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.8 ]

columnIndex

Gets the zero-based column index of the cell within the table.

readonly columnIndex: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.8 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

fill

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the fill color of the table cell.

readonly fill: PowerPoint.ShapeFill;

Property Value

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

font

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the font of the table cell.

readonly font: PowerPoint.ShapeFont;

Property Value

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

horizontalAlignment

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Specifies the horizontal alignment of the text in the table cell.

horizontalAlignment: PowerPoint.ParagraphHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed";

Property Value

PowerPoint.ParagraphHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed"

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

indentLevel

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Specifies the indent level of the text in the table cell.

indentLevel: number;

Property Value

number

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

margins

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the set of margins in the table cell.

readonly margins: PowerPoint.Margins;

Property Value

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

rowCount

Gets the number of table rows this cell spans across. Will be greater than or equal to 1.

readonly rowCount: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.8 ]

rowIndex

Gets the zero-based row index of the cell within the table.

readonly rowIndex: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.8 ]

text

Specifies the text content of the table cell.

text: string;

Property Value

string

Remarks

[ API set: PowerPointApi 1.8 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/add-modify-tables.yaml

// Updates a table's values.
await PowerPoint.run(async (context) => {
  const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;

  // Add a table (which is a type of Shape).
  const shape = shapes.addTable(4, 3);
  let table = shape.getTable();
  table.load();
  await context.sync();

  // Update values in the table.
  for (let rowIndex = 0; rowIndex < table.rowCount; rowIndex++) {
    for (let columnIndex = 0; columnIndex < table.columnCount; columnIndex++) {
      const cell = table.getCellOrNullObject(rowIndex, columnIndex);
      cell.text = generateRandomString();
    }
  }

  await context.sync();
});

textRuns

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Specifies the contents of the table cell as an array of objects. Each TextRun object represents a sequence of one or more characters that share the same font attributes.

textRuns: PowerPoint.TextRun[];

Property Value

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

verticalAlignment

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Specifies the vertical alignment of the text in the table cell.

verticalAlignment: PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered";

Property Value

PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered"

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

Method Details

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: PowerPoint.Interfaces.TableCellLoadOptions): PowerPoint.TableCell;

Parameters

options
PowerPoint.Interfaces.TableCellLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): PowerPoint.TableCell;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.TableCell;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

resize(rowCount, columnCount)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Resizes the table cell to span across a specified number of rows and columns. If rowCount or columnCount are greater than 1, the cell will become a merged area. If the cell is already a merged area and rowCount and columnCount are set to 1, the cell will no longer be a merged area.

resize(rowCount: number, columnCount: number): void;

Parameters

rowCount

number

The number of rows the cell will span across. Must be greater than 0.

columnCount

number

The number of columns the cell will span across. Must be greater than 0.

Returns

void

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

split(rowCount, columnCount)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Splits the cell into the specified number of rows and columns.

split(rowCount: number, columnCount: number): void;

Parameters

rowCount

number

The number of rows to split into. Must be greater than 0.

columnCount

number

The number of columns to split into. Must be greater than 0.

Returns

void

Remarks

[ API set: PowerPointApi BETA (PREVIEW ONLY) ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original PowerPoint.TableCell object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.TableCellData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): PowerPoint.Interfaces.TableCellData;

Returns