Set PowerPoint Table Alignment with JavaScript in React
Tables are a common element for carrying structured content in a presentation, and where a table sits on the slide directly affects the balance of the layout: pinned to a page edge, centered, or lined up with other elements, each reads differently. Dragging a table into place by hand is rarely precise, and it is hard to land it exactly on the layout's center line.
This article uses Spire.Presentation for JavaScript to adjust where a PowerPoint table sits on a slide in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
The two core features covered are:
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Set the horizontal alignment of a PowerPoint table
Horizontal alignment decides whether a table is pinned to the left of the slide, centered, or pinned to the right. When a table on a page must line up with the layout's center line, or sit consistently on one side, dragging it rarely gives a precise position; specifying it once with SetShapeAlignment sends the table to the matching horizontal position on the slide. The three values correspond to flush left, horizontal center, and flush right.
| Code | Result |
|---|---|
table.SetShapeAlignment(ShapeAlignment.AlignLeft) |
The table's left edge aligns with the slide's left edge |
table.SetShapeAlignment(ShapeAlignment.AlignCenter) |
The table is centered horizontally on the slide |
table.SetShapeAlignment(ShapeAlignment.AlignRight) |
The table's right edge aligns with the slide's right edge |
The steps are:
- Get the Spire.Presentation WASM module and confirm it is ready, load the presentation into the VFS, then open it with
LoadFromFile()and get the first slide. - Iterate over
slide.Shapes, test whether a shape is a table withshape instanceof pptModule.ITable, and get the table object. - Call
SetShapeAlignment()withShapeAlignment.AlignCenterto center the table horizontally on the slide; useAlignLeftorAlignRightfor the left or right edge. - Call
Presentation.SaveToFile()to save the result file, release the presentation withDispose(), then read the file from the VFS and trigger the download.
The code for setting the horizontal alignment of a PowerPoint table is shown below:
function App() {
// set the horizontal alignment of a PowerPoint table
const alignHorizontally = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check whether the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation into the VFS
const inputFileName = 'en_TableAlignment.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// open the presentation and get the first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// iterate over the shapes and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// center the table horizontally on the slide (or use AlignLeft / AlignRight for the left / right edge)
table.SetShapeAlignment(pptModule.ShapeAlignment.AlignCenter);
// save the result file
const outputFileName = 'HorizontalAlignment_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and trigger the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and trigger the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Align PowerPoint Tables</h1>
<button onClick={alignHorizontally}>Horizontal</button>
</div>
);
}
export default App;
The presentation after centering the table horizontally:

Set the vertical alignment of a PowerPoint table
Vertical alignment decides whether a table is pinned to the top of the slide, centered, or pinned to the bottom. When a table is shorter than the page and there is plenty of whitespace above and below, this difference is the most visible: a top-aligned table hugs the upper edge, a centered one falls in the middle, and a bottom-aligned one sits near the lower edge. It only adjusts the vertical position and leaves the table's horizontal placement untouched.
| Code | Result |
|---|---|
table.SetShapeAlignment(ShapeAlignment.AlignTop) |
The table's top edge aligns with the slide's top edge |
table.SetShapeAlignment(ShapeAlignment.AlignMiddle) |
The table is centered vertically on the slide |
table.SetShapeAlignment(ShapeAlignment.AlignBottom) |
The table's bottom edge aligns with the slide's bottom edge |
The steps are:
- Get the Spire.Presentation WASM module and confirm it is ready, load the presentation into the VFS, then open it with
LoadFromFile()and get the first slide. - Iterate over
slide.Shapes, test whether a shape is a table withshape instanceof pptModule.ITable, and get the table object. - Call
SetShapeAlignment()withShapeAlignment.AlignMiddleto center the table vertically on the slide; useAlignToporAlignBottomfor the top or bottom edge. - Call
Presentation.SaveToFile()to save the result file, release the presentation withDispose(), then read the file from the VFS and trigger the download.
The code for setting the vertical alignment of a PowerPoint table is shown below:
function App() {
// set the vertical alignment of a PowerPoint table
const alignVertically = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check whether the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation into the VFS
const inputFileName = 'en_TableAlignment.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// open the presentation and get the first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// iterate over the shapes and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// center the table vertically on the slide (or use AlignTop / AlignBottom for the top / bottom edge)
table.SetShapeAlignment(pptModule.ShapeAlignment.AlignMiddle);
// save the result file
const outputFileName = 'VerticalAlignment_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and trigger the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and trigger the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Align PowerPoint Tables</h1>
<button onClick={alignVertically}>Vertical</button>
</div>
);
}
export default App;
The presentation after centering the table vertically:

FAQ
How to center a table both horizontally and vertically on the slide
Cause: SetShapeAlignment adjusts only one direction per call — AlignCenter handles horizontal centering and AlignMiddle handles vertical centering — so a single call cannot do both at once.
Resolution: Call AlignCenter and then AlignMiddle on the same table; the two settings stack and the table lands in the center of the slide:
table.SetShapeAlignment(pptModule.ShapeAlignment.AlignCenter);
table.SetShapeAlignment(pptModule.ShapeAlignment.AlignMiddle);
How to place a table at an arbitrary coordinate
Cause: SetShapeAlignment only offers relative positions such as edge and center, and cannot target an arbitrary precise coordinate.
Resolution: Assign point values directly to table.Left and table.Top to place the table at a specified position on the slide, for example:
table.Left = 200;
table.Top = 120;
Does alignment, which only changes position, affect the text and style inside the table
Cause: SetShapeAlignment adjusts the position of the table as a whole on the slide, and acts on the shape itself.
Resolution: A table's cell text, fonts, fills and borders are not affected by the alignment operation, and the cell text stays the same before and after; to adjust the content or formatting as well, set the cell properties separately.
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Set Text Alignment in PowerPoint Tables with JavaScript in React
Tables are a common way to present structured content on a slide, and where the text sits inside a cell directly affects readability: body columns are usually left aligned, numeric columns right aligned, and header rows centered, while each column is also nudged up or down to suit its content. Adjusting every cell by hand becomes hard to keep consistent once a table grows, and the same work repeats for the next deck.
This article uses Spire.Presentation for JavaScript to set the text alignment of PowerPoint tables in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers three core features:
- Set the Horizontal Alignment of Table Text
- Set the Vertical Alignment of Table Text
- Set Both Horizontal and Vertical Alignment
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Set the Horizontal Alignment of Table Text
Horizontal alignment decides whether text sits at the left, center or right of a cell, or is stretched across the full width. Columns that hold different kinds of content often need different positions, and assigning them column by column lines similar items up along one vertical edge while separating values from labels. It is set paragraph by paragraph, so changing one column leaves the others untouched.
| Syntax | Result |
|---|---|
paragraph.Alignment = TextAlignmentType.Left |
Aligns the paragraph text to the left of the cell |
paragraph.Alignment = TextAlignmentType.Center |
Centers the paragraph text horizontally in the cell |
paragraph.Alignment = TextAlignmentType.Right |
Aligns the paragraph text to the right of the cell |
paragraph.Alignment = TextAlignmentType.Justify |
Justifies the paragraph text, spreading spacing to fill the line |
The steps are:
- Get the Spire.Presentation WASM module and make sure it is ready, load the presentation into the VFS, then open it with
LoadFromFile()and get the first slide. - Walk
slide.Shapesand useshape instanceof pptModule.ITableto tell whether a shape is a table, and keep the table object. - Loop over the columns of one data row, take
TextFrame.Paragraphs.get_Item(0)of each cell, and setAlignmenttoTextAlignmentType.Left,Center,RightandJustifyin turn. - Call
Presentation.SaveToFile()to save the result, release the presentation withDispose(), then read the file from the VFS to trigger the download.
The following code sets the horizontal alignment of table text:
function App() {
const setHorizontalAlignment = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TextAlignment.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// set the horizontal alignment of the first data row column by column
const alignments = [
pptModule.TextAlignmentType.Left,
pptModule.TextAlignmentType.Center,
pptModule.TextAlignmentType.Right,
pptModule.TextAlignmentType.Justify,
];
for (let col = 1; col <= 4; col++) {
table.get_Item(col, 1).TextFrame.Paragraphs.get_Item(0).Alignment = alignments[col - 1];
}
// save the result file
const outputFileName = 'HorizontalAlignment_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Text Alignment in PowerPoint Tables</h1>
<button onClick={setHorizontalAlignment}>Horizontal</button>
</div>
);
}
export default App;
The presentation after setting the horizontal alignment of the first data row:

Set the Vertical Alignment of Table Text
Vertical alignment decides whether text hugs the top of a cell, sits in the middle or drops to the bottom. It shows most clearly when the row is taller than the text: short text at the top sticks to the upper edge, centered text lands in the middle, and bottom-aligned text approaches the lower edge. It is set at the cell level and is independent of the paragraph-level horizontal alignment.
| Syntax | Result |
|---|---|
cell.TextAnchorType = TextAnchorType.Top |
Aligns the cell text to the top |
cell.TextAnchorType = TextAnchorType.Center |
Centers the cell text vertically |
cell.TextAnchorType = TextAnchorType.Bottom |
Aligns the cell text to the bottom |
The steps are:
- Get the Spire.Presentation WASM module and make sure it is ready, load the presentation into the VFS, then open it with
LoadFromFile()and get the first slide. - Walk
slide.Shapesand useshape instanceof pptModule.ITableto tell whether a shape is a table, and keep the table object. - Loop over the columns of one data row and set each cell's
TextAnchorTypetoTextAnchorType.Top,CenterandBottomin turn. - Call
Presentation.SaveToFile()to save the result, release the presentation withDispose(), then read the file from the VFS to trigger the download.
The following code sets the vertical alignment of table text:
function App() {
const setVerticalAlignment = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TextAlignment.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// set the vertical alignment of the second data row column by column
const anchors = [
pptModule.TextAnchorType.Top,
pptModule.TextAnchorType.Center,
pptModule.TextAnchorType.Bottom,
];
for (let col = 1; col <= 3; col++) {
table.get_Item(col, 2).TextAnchorType = anchors[col - 1];
}
// save the result file
const outputFileName = 'VerticalAlignment_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Text Alignment in PowerPoint Tables</h1>
<button onClick={setVerticalAlignment}>Vertical</button>
</div>
);
}
export default App;
The presentation after setting the vertical alignment of the second data row:

Set Both Horizontal and Vertical Alignment
In real layouts the horizontal and vertical positions are often decided together: a label at the top-left, emphasis text in the exact center, or a value at the bottom-right are all results of combining the two. Horizontal alignment lives on the paragraph and vertical alignment on the cell, so assigning both gives the combined effect; setting them cell by cell lets each column of the same table use a different arrangement.
| Syntax | Result |
|---|---|
paragraph.Alignment = TextAlignmentType.Left and cell.TextAnchorType = TextAnchorType.Top |
Text aligned to the top-left |
paragraph.Alignment = TextAlignmentType.Center and cell.TextAnchorType = TextAnchorType.Center |
Text centered both horizontally and vertically |
paragraph.Alignment = TextAlignmentType.Right and cell.TextAnchorType = TextAnchorType.Bottom |
Text aligned to the bottom-right |
paragraph.Alignment = TextAlignmentType.Justify and cell.TextAnchorType = TextAnchorType.Center |
Text justified and vertically centered |
The steps are:
- Get the Spire.Presentation WASM module and make sure it is ready, load the presentation into the VFS, then open it with
LoadFromFile()and get the first slide. - Walk
slide.Shapesand useshape instanceof pptModule.ITableto tell whether a shape is a table, and keep the table object. - For every cell of that row assign both at once: set
TextFrame.Paragraphs.get_Item(0).Alignmentto aTextAlignmentTypevalue andTextAnchorTypeto aTextAnchorTypevalue, pairing them. - Call
Presentation.SaveToFile()to save the result, release the presentation withDispose(), then read the file from the VFS to trigger the download.
The following code sets both the horizontal and vertical alignment of table text:
function App() {
const setBothAlignments = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TextAlignment.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// set the horizontal and the vertical alignment of every cell in the third data row
table.get_Item(1, 3).TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Left;
table.get_Item(1, 3).TextAnchorType = pptModule.TextAnchorType.Top;
table.get_Item(2, 3).TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Center;
table.get_Item(2, 3).TextAnchorType = pptModule.TextAnchorType.Center;
table.get_Item(3, 3).TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Right;
table.get_Item(3, 3).TextAnchorType = pptModule.TextAnchorType.Bottom;
table.get_Item(4, 3).TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Justify;
table.get_Item(4, 3).TextAnchorType = pptModule.TextAnchorType.Center;
// save the result file
const outputFileName = 'BothAlignments_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Text Alignment in PowerPoint Tables</h1>
<button onClick={setBothAlignments}>Combined</button>
</div>
);
}
export default App;
The presentation after setting both the horizontal and vertical alignment:

FAQ
How do I align a cell that holds several paragraphs
Reason: Alignment belongs to a paragraph, not a cell. When a cell holds more than one paragraph, setting only the first one leaves the others unchanged.
Solution: Read TextFrame.Paragraphs.Count first, then set Alignment on each paragraph by index:
const paragraphs = cell.TextFrame.Paragraphs;
for (let p = 0; p < paragraphs.Count; p++) {
paragraphs.get_Item(p).Alignment = pptModule.TextAlignmentType.Center;
}
How do I align a merged cell
Reason: Once cells are merged, several positions in the merged area actually point to the same cell, so setting each one repeats the work; to change the alignment you only need to target the merged cell itself.
Solution: A merged cell can be located through FirstRowIndex and FirstColumnIndex, or taken directly with table.get_Item() using the anchor position at the top-left of the merged area; set its TextFrame.Paragraphs.get_Item(0).Alignment and TextAnchorType, and after saving, positions covered by the merge still read back the same cell with the alignment kept:
const merged = table.get_Item(column, row); // column and row are the top-left of the merged area
merged.TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Center;
merged.TextAnchorType = pptModule.TextAnchorType.Center;
Why does nothing change after setting Justify alignment
Reason: TextAlignmentType.Justify stretches every line except the last. When the cell text is a single line, or already nearly fills the line, there is no spare space to stretch, so it looks almost the same as the default alignment.
Solution: To see the justify effect, let the cell text wrap onto several lines and narrow the column a little so the inner lines have gaps to stretch; if only the left-to-right position of a single line matters, TextAlignmentType.Left, Center or Right is more direct.
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Insert Pictures into PowerPoint Table Cells in React
Tables in a slide deck often carry portraits, product shots or stamps. Inserting a picture cell by cell and then dragging it into place takes time as soon as the rows pile up, and keeping the scale uniform is hard; nudge the table width and gaps appear between the picture and the cell. Used as the fill of a cell, a picture becomes part of the cell: it follows the row height and column width, and the table always looks tidy.
This article uses Spire.Presentation for JavaScript to insert pictures into PowerPoint table cells in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers two features:
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Insert a picture into a PowerPoint table cell
A picture used as a cell fill shares the cell's area: when the row height or the column width changes, the picture follows and leaves no blank edge. The picture is embedded only once and can serve several cells, so the file does not grow with every copy. The stretch fill spreads the picture over the whole cell, which suits portraits and thumbnails that should be shown in full.
| What you write | What you get |
|---|---|
new pptModule.Stream(imgFileName) |
Opens a file stream for the picture in the VFS |
ppt.Images.Append({ stream: stream }) |
Embeds the picture from the stream and returns it |
cell.FillFormat.FillType = pptModule.FillFormatType.Picture |
Makes the fill of the cell a picture |
cell.FillFormat.PictureFill.Picture.EmbedImage = image |
Uses the embedded picture as the fill |
cell.FillFormat.PictureFill.FillType = pptModule.PictureFillType.Stretch |
Stretches the picture over the whole cell |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the presentation and the picture into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Countand find the table withshape instanceof pptModule.ITable. - Open the picture with
new pptModule.Stream(), embed it withppt.Images.Append(), then close the stream withstream.Close(). - Walk the icon cells row by row, set
cell.FillFormat.FillTypetoFillFormatType.Picture, choose the picture withPictureFill.Picture.EmbedImageand setPictureFill.FillTypetoPictureFillType.Stretch. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code that inserts a picture into a PowerPoint table cell is as follows:
function App() {
// insert a picture into a PowerPoint table cell
const insertCellImage = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation and the picture into the VFS
const inputFileName = 'en_CellImage.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
const imgFileName = 'photo.png';
await window.spire.FetchFileToVFS(imgFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// read the picture from a file stream and embed it
const stream = new pptModule.Stream(imgFileName);
const image = ppt.Images.Append({ stream: stream });
stream.Close();
// fill the icon cells with the picture, stretched to the cell size
for (let row = 1; row < table.TableRows.Count; row++) {
const cell = table.get_Item(1, row);
cell.FillFormat.FillType = pptModule.FillFormatType.Picture;
cell.FillFormat.PictureFill.Picture.EmbedImage = image;
cell.FillFormat.PictureFill.FillType = pptModule.PictureFillType.Stretch;
}
// save the result file
const outputFileName = 'InsertCellImage_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and start the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Pictures in PowerPoint Table Cells</h1>
<button onClick={insertCellImage}>Insert a picture</button>
</div>
);
}
export default App;
Presentation after inserting a picture into a PowerPoint table cell:

Crop the picture in a PowerPoint table cell
Only part of the original picture is often needed; stretching the whole frame would enlarge the empty margins along with it. The crop area is described as a relative rectangle: the position of the top-left corner and the width and height are given as ratios of the picture's sides, between 0 and 1. Shrinking that rectangle keeps only the matching part of the picture and drops the rest, so the cell shows a close-up.
| What you write | What you get |
|---|---|
cell.FillFormat.PictureFill.SourceRectangle |
Gets the crop area of the picture as a relative rectangle |
cropArea.X = 0.2 |
The left edge of the crop area sits two tenths in from the left |
cropArea.Y = 0.1 |
The top edge sits one tenth down from the top |
cropArea.Width = 0.6 |
The crop area spans six tenths of the picture's width |
cropArea.Height = 0.6 |
The crop area spans six tenths of the picture's height |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the presentation and the picture into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Countand find the table withshape instanceof pptModule.ITable. - Open the picture with
new pptModule.Stream(), embed it withppt.Images.Append(), then close the stream withstream.Close(). - Walk the icon cells, set them to a picture fill with
Stretch, takePictureFill.SourceRectangleand setX,Y,WidthandHeightso that only the middle part of the picture is kept. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code that crops the picture in a PowerPoint table cell is as follows:
function App() {
// crop the picture in a table cell
const cropCellImage = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation and the picture into the VFS
const inputFileName = 'en_CellImage.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
const imgFileName = 'photo.png';
await window.spire.FetchFileToVFS(imgFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// read the picture from a file stream and embed it
const stream = new pptModule.Stream(imgFileName);
const image = ppt.Images.Append({ stream: stream });
stream.Close();
// fill the icon cells and keep only the middle area of the icon
for (let row = 1; row < table.TableRows.Count; row++) {
const cell = table.get_Item(1, row);
cell.FillFormat.FillType = pptModule.FillFormatType.Picture;
cell.FillFormat.PictureFill.Picture.EmbedImage = image;
cell.FillFormat.PictureFill.FillType = pptModule.PictureFillType.Stretch;
const cropArea = cell.FillFormat.PictureFill.SourceRectangle;
cropArea.X = 0.2;
cropArea.Y = 0.1;
cropArea.Width = 0.6;
cropArea.Height = 0.6;
}
// save the result file
const outputFileName = 'CropCellImage_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and start the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Pictures in PowerPoint Table Cells</h1>
<button onClick={cropCellImage}>Crop the picture</button>
</div>
);
}
export default App;
Presentation after cropping the picture in a PowerPoint table cell:

FAQ
How do I remove a picture fill from a cell
Cause: A picture fill is one of the fill types of the cell; making the cell blank again takes a change of the fill type, not the removal of the picture object.
Solution: Set cell.FillFormat.FillType to FillFormatType.None and the cell goes back to an empty fill:
cell.FillFormat.FillType = pptModule.FillFormatType.None;
Does the text in a cell get hidden behind the picture
Cause: The picture fill sits at the bottom of the cell, while the text is content of the cell, and the two are stored in separate layers.
Solution: Nothing extra is needed. After the picture fill is applied, the text of the cell still shows above the picture; clear TextFrame.Text if a blank area is wanted instead.
Does the picture distort when rows and columns are resized
Cause: A picture fill is attached to the cell, so the fill area changes together with the cell.
Solution: With PictureFillType.Stretch the picture stretches along with the cell; to keep the pattern in proportion, use PictureFillType.Tile with a fixed scale instead.
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Insert and Delete PowerPoint Table Rows and Columns in React
Tables in presentations grow and shrink with the data behind them: an extra metric calls for another column, an extra entry calls for another row, and reusing an old template means clearing out stale records and fields. Adding or removing rows and columns by hand is slow and easily throws the row heights, column widths and cell formatting out of step, and a deck with several tables rarely stays consistent.
This article uses Spire.Presentation for JavaScript to insert and delete rows and columns in PowerPoint tables in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers three features:
- Insert a Row into a PowerPoint Table
- Insert a Column into a PowerPoint Table
- Delete Rows and Columns from a PowerPoint Table
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Insert a Row into a PowerPoint Table
When a new record has to go into the middle of a table, starting from a blank line does not line up with the rows around it: the height, the typeface and the shading all have to be set again, and the result rarely matches the rest of the table. Copying an existing row as a sample and inserting that copy at the chosen position gives a new row that keeps the sample row's height and cell formatting, so only the text has to be rewritten. The position is set by an index, and once the new row is in place the rows after it move down, so later cell lookups have to use the new numbering.
| Call | Result |
|---|---|
slide.Shapes.get_Item(index) |
Gets a shape on the slide by index |
shape instanceof pptModule.ITable |
Checks whether the shape is a table |
table.TableRows.Count |
Current number of rows in the table |
table.TableRows.get_Item(index) |
Gets a row by index, counting from 0 |
table.TableRows.Insert(index, row) |
Inserts a copy of the given row at that index |
row.get_Item(columnIndex) |
Gets the cell at the given column of the row |
cell.TextFrame.Text |
Sets or reads the text of the cell |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject, load the deck withLoadFromFile()and take the first slide withSlides.get_Item(0). - Walk the shape collection and find the table on the slide with
shape instanceof pptModule.ITable. - Take a row with
table.TableRows.get_Item()and hand it totable.TableRows.Insert()to insert a copy at the target index; the sample row does not have to be next to the insertion point. - Take the new row back with
table.TableRows.get_Item()and write the text of each cell intocell.TextFrame.Text, replacing what came with the sample row. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code for inserting a row into a PowerPoint table is as follows:
function App() {
const insertRow = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableRowsColumns.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// find the table on the slide
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
}
}
// use the second row as a sample and insert it as the fourth row
table.TableRows.Insert(3, table.TableRows.get_Item(1));
// take back the new row and write the new record cell by cell
const newRow = table.TableRows.get_Item(3);
const rowData = ['Deployment', 'Emma Clark', 'Aug 1', 'Aug 15', 'Not Started'];
for (let col = 0; col < rowData.length; col++) {
newRow.get_Item(col).TextFrame.Text = rowData[col];
}
// save the result file
const outputFileName = 'InsertRow_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Working with Table Rows and Columns in PowerPoint</h1>
<button onClick={insertRow}>Insert a row</button>
</div>
);
}
export default App;
Presentation after inserting a row into the table:

Insert a Column into a PowerPoint Table
When a table needs a new field, adding text on the right is not enough to form a column: the width, the borders and the shading have to match the neighbouring columns. The column collection works the same way as the row collection, taking an existing column as a sample and inserting a copy at the chosen position. The new column keeps the sample column's width and cell formatting, and the table grows wider by exactly that amount, so leave the horizontal space free before inserting if the table already reaches the edge of the slide.
| Call | Result |
|---|---|
table.ColumnsList.Count |
Current number of columns in the table |
table.ColumnsList.get_Item(index) |
Gets a column by index, counting from 0 |
table.ColumnsList.Insert(index, column) |
Inserts a copy of the given column at that index |
table.get_Item(columnIndex, rowIndex) |
Gets the cell at the given column and row |
cell.TextFrame.Text |
Sets or reads the text of the cell |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject, load the deck withLoadFromFile()and take the first slide withSlides.get_Item(0). - Walk the shape collection and find the table on the slide with
shape instanceof pptModule.ITable. - Take a column with
table.ColumnsList.get_Item()and hand it totable.ColumnsList.Insert()to insert a copy at the target index. - With the new column index, go through the rows with
table.get_Item()and write the text intocell.TextFrame.Text, replacing what came with the sample column. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code for inserting a column into a PowerPoint table is as follows:
function App() {
const insertColumn = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableRowsColumns.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// find the table on the slide
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
}
}
// use the fifth column as a sample and insert it as the third column
table.ColumnsList.Insert(2, table.ColumnsList.get_Item(4));
// write the new field row by row under the new column index
const columnData = ['Completion', '100%', '100%', '65%', '0%'];
for (let row = 0; row < columnData.length; row++) {
table.get_Item(2, row).TextFrame.Text = columnData[row];
}
// save the result file
const outputFileName = 'InsertColumn_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Working with Table Rows and Columns in PowerPoint</h1>
<button onClick={insertColumn}>Insert a column</button>
</div>
);
}
export default App;
Presentation after inserting a column into the table:

Delete Rows and Columns from a PowerPoint Table
When an old table is reused, stale records and fields have to go, while titles, pictures and other shapes on the slide stay untouched. The row and column collections each offer an index-based removal call: one call drops one row or one column, and everything else keeps its content. After a removal the following entries move up, and the table narrows as columns disappear, so delete several spots starting from the end to keep the indexes from shifting during the operation.
| Call | Result |
|---|---|
table.TableRows.Count |
Current number of rows in the table |
table.ColumnsList.Count |
Current number of columns in the table |
table.TableRows.RemoveAt(index, false) |
Deletes the row at the index |
table.ColumnsList.RemoveAt(index, false) |
Deletes the column at the index |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject, load the deck withLoadFromFile()and take the first slide withSlides.get_Item(0). - Walk the shape collection and find the table on the slide with
shape instanceof pptModule.ITable. - Call
table.TableRows.RemoveAt()to delete rows that are no longer needed andtable.ColumnsList.RemoveAt()to delete columns that are no longer needed; each call drops one row or one column. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code for deleting rows and columns from a PowerPoint table is as follows:
function App() {
const removeRowsAndColumns = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableRowsColumns.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// find the table on the slide
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
}
}
// delete the third row and the fourth column
table.TableRows.RemoveAt(2, false);
table.ColumnsList.RemoveAt(3, false);
// save the result file
const outputFileName = 'RemoveRowsColumns_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Working with Table Rows and Columns in PowerPoint</h1>
<button onClick={removeRowsAndColumns}>Delete rows and columns</button>
</div>
);
}
export default App;
Presentation after deleting a row and a column from the table:

Frequently Asked Questions
How do I append a row or column at the end of a table
Cause: Insert() places the copy at a given index, so appending at the end still means working out the last index first.
Solution: To add to the end directly, use TableRows.Append() and ColumnsList.Add() with the sample row or column; the new row or column is placed after the last one in the table:
table.TableRows.Append(table.TableRows.get_Item(1));
table.ColumnsList.Add(table.ColumnsList.get_Item(1));
How do I insert several rows or columns at once
Cause: Insert() and Append() handle one row or one column per call, so a larger number of new rows or columns has to be added in several calls.
Solution: Put the insertion in a loop and repeat it as many times as the number of rows or columns to add; with the index moving forward each time, the new rows and columns end up side by side:
for (let i = 0; i < 2; i++) {
table.TableRows.Insert(2 + i, table.TableRows.get_Item(1));
}
for (let i = 0; i < 2; i++) {
table.ColumnsList.Insert(2 + i, table.ColumnsList.get_Item(1));
}
How do I set the height and width of an inserted row or column
Cause: A new row keeps the height of its sample row and a new column keeps the width of its sample column; changing either means taking the row or column from its collection first.
Solution: TableRows and ColumnsList both get rows and columns by index (counting from 0); set Height and Width on them and the total height and width of the table follow:
table.TableRows.get_Item(1).Height = 60;
table.ColumnsList.get_Item(0).Width = 90;
How do I clear a table's content but keep its rows and columns
Cause: Sometimes only the structure and styling of a table are reused and all of the text has to go; removing rows or columns would change the structure.
Solution: Loop over the current row and column counts and set TextFrame.Text of every cell to an empty string; the row heights, column widths and styling stay as they are:
for (let row = 0; row < table.TableRows.Count; row++) {
for (let col = 0; col < table.ColumnsList.Count; col++) {
table.get_Item(col, row).TextFrame.Text = '';
}
}
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Merge and Split PowerPoint Table Cells with JavaScript in React
When several rows share one label, or a line of explanation has to stretch across a few columns, merging cells makes the structure easier to read; after the header or the content changes, an oversized cell has to be divided back into smaller ones. Merging and splitting cells by hand, dragging the mouse across the grid again and again, takes time and easily drags neighbouring cells along, and keeping several presentations consistent is even harder.
This article uses Spire.Presentation for JavaScript to merge and split PowerPoint table cells in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers two features:
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Merge cells in a PowerPoint table
Merging joins every cell inside a rectangle into one cell: a vertical merge lets a single label cover several rows, and a horizontal merge lets one line of text run across a whole row. MergeCells takes the two opposite corner cells of the region, so one call fixes the whole range; the number of rows and columns the merged cell now covers can be read back from RowSpan and ColSpan to confirm the result.
| Call | Result |
|---|---|
slide.Shapes.get_Item(index) |
Take a shape on the slide by index |
shape instanceof pptModule.ITable |
Tell whether a shape is a table |
table.get_Item(columnIndex, rowIndex) |
Take a cell by column and row index |
table.MergeCells(cell1, cell2, allowSplitting) |
Merge the region defined by two cells |
cell.RowSpan / cell.ColSpan |
Number of rows and columns the merged cell spans |
cell.FirstRowIndex / cell.FirstColumnIndex |
Row and column index of the top-left cell of the merged region |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the presentation into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection and find the table on the slide with
shape instanceof pptModule.ITable. - For a vertical merge, pass the first and the last cell of the column to
table.MergeCells(); the example merges the second and third rows of the first column. - For a horizontal merge, pass the first and the last cell of the row to
table.MergeCells(); the example merges every cell of the last row. - Call
Presentation.SaveToFile()to save the result file andDispose()to release the presentation, then read the file back from the VFS and start the download.
The code that merges cells in a PowerPoint table:
function App() {
const mergeCells = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation into the VFS
const inputFileName = 'en_TableCells.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// find the table on the slide
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
}
}
// merge vertically: the second and third rows of the first column
table.MergeCells(table.get_Item(0, 1), table.get_Item(0, 2), false);
// merge horizontally: every cell of the last row
table.MergeCells(table.get_Item(0, 4), table.get_Item(3, 4), true);
// save the result file
const outputFileName = 'MergeCells_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Merge and Split Table Cells in PowerPoint</h1>
<button onClick={mergeCells}>Merge cells</button>
</div>
);
}
export default App;
The presentation after merging cells:

Split a cell in a PowerPoint table
Splitting divides the area of one cell into the given number of rows and columns, turning a single cell into several smaller ones. The table gains the matching rows and columns, and the cells next to the split area stretch across the new dividing lines while keeping their content; the newly created cells are empty and ready for new text. That makes it possible to break an oversized cell into finer columns, or to open up extra places to fill in a fixed layout.
| Call | Result |
|---|---|
table.get_Item(columnIndex, rowIndex) |
Take the cell to split by column and row index |
cell.Split(rowCount, columnCount) |
Split the cell into the given number of rows and columns |
cell.RowSpan / cell.ColSpan |
Span of each cell after the split |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the presentation into the VFS, create a
Presentationobject and load the presentation, then take the first slide. - Walk the shape collection and find the table with
shape instanceof pptModule.ITable. - Take the cell to split with
table.get_Item()and callSplit()with the row and column counts; the example splits it into 2 rows and 2 columns. - Call
Presentation.SaveToFile()to save the result file andDispose()to release the presentation, then read the file back from the VFS and start the download.
The code that splits a cell in a PowerPoint table:
function App() {
const splitCell = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation into the VFS
const inputFileName = 'en_TableCells.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// find the table on the slide
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
}
}
// split the cell in the third row and second column into 2 rows and 2 columns
table.get_Item(1, 2).Split(2, 2);
// save the result file
const outputFileName = 'SplitCell_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Merge and Split Table Cells in PowerPoint</h1>
<button onClick={splitCell}>Split the cell</button>
</div>
);
}
export default App;
The presentation after splitting a cell:

FAQ
How do I restore a merged cell to separate cells
Cause: Merging only changes the span of the cell; the content of the original cells stays in the merged one, so the span has to be reset to a single cell.
Solution: Call SplitBySpan() on the merged cell; it restores the region to independent cells according to the current span, without changing the row and column counts of the table:
table.get_Item(0, 1).SplitBySpan();
Are the texts of every cell kept after merging
Cause: A merged cell holds one block of text, so the texts already in the region have to be reorganized.
Solution: When cells are merged, the texts of the region are joined into the merged cell as separate paragraphs, and empty cells do not affect the result. If only one label should remain, clear the texts that are no longer needed before merging:
table.get_Item(0, 2).TextFrame.Text = '';
table.MergeCells(table.get_Item(0, 1), table.get_Item(0, 2), false);
How do I tell whether a cell belongs to a merged region
Cause: Every position inside a merged region reads back the same cell object, so the text alone cannot tell whether it spans several rows or columns.
Solution: Read RowSpan and ColSpan; a value greater than 1 means the cell is merged, and FirstRowIndex together with FirstColumnIndex gives the top-left corner of the region:
const cell = table.get_Item(col, row);
if (cell.RowSpan > 1 || cell.ColSpan > 1) {
console.log(cell.FirstRowIndex, cell.FirstColumnIndex);
}
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Create and Delete PowerPoint Tables with JavaScript in React
Parameters, checklists and summary figures are easier to read in a table than in a paragraph of text. Inserting tables page by page and filling every cell by hand takes time, and across a longer deck the row and column counts drift apart and the styling no longer matches; when an old template is reused, the tables left over from the previous version have to be cleared out as well.
This article uses Spire.Presentation for JavaScript to create and delete PowerPoint tables in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers two features:
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Add a table to a PowerPoint slide
A new presentation comes with one blank slide, and a table's position, column widths and row heights are all fixed at the moment it is inserted. Give the width of each column and the height of each row according to the number of rows and columns, then write the text cell by cell, and the table lands exactly where it is expected on the page. Applying a built-in table style lets the header row and the detail rows differ in fill color automatically, without setting borders and fills cell by cell, and keeps the tables on different slides consistent.
| Call | Result |
|---|---|
Presentation.Slides.get_Item(index) |
Take a slide by index, starting from 0 |
slide.Shapes.AppendTable(x, y, widths, heights) |
Add a table at the given position with the given column widths and row heights |
table.get_Item(columnIndex, rowIndex) |
Take a cell by column and row index |
cell.TextFrame.Text |
Set or read the text of a cell |
cell.TextFrame.Paragraphs.get_Item(0).TextRanges.get_Item(0) |
Take the text range of the cell's first paragraph, used for font settings |
textRange.LatinFont |
Set the font of the text range |
paragraph.Alignment = TextAlignmentType.Center |
Center the paragraph horizontally |
table.StylePreset = TableStylePreset.MediumStyle1Accent2 |
Apply a built-in table style |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file into the VFS, then create a
Presentationobject and take its first slide withSlides.get_Item(0). - Prepare the column width and row height arrays and call
slide.Shapes.AppendTable()to add the table; the returned object is what the values are written through. - Walk the data row by row and column by column, take each cell with
table.get_Item(), write the text intocell.TextFrame.Text, and setLatinFontthroughTextRanges.get_Item(0). - Set the
Alignmentof the header row's paragraphs toTextAlignmentType.Center, then setStylePresettoTableStylePreset.MediumStyle1Accent2. - Call
Presentation.SaveToFile()to save the result file andDispose()to release the presentation, then read the file back from the VFS and start the download.
The code that adds a table to a PowerPoint slide:
function App() {
const addTable = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font into the VFS
await window.spire.FetchFileToVFS('arial.ttf', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
// create a presentation and take its first slide
const ppt = new pptModule.Presentation();
const slide = ppt.Slides.get_Item(0);
// define the width of the four columns and the height of the five rows (in points)
const widths = [150, 150, 150, 150];
const heights = [40, 40, 40, 40, 40];
// add a four-column, five-row table at the given position
const table = slide.Shapes.AppendTable(60, 120, widths, heights);
// prepare the data to write into the table, the first row is the header
const data = [
['Product', 'January', 'February', 'March'],
['Laptop', '320', '368', '402'],
['Desktop', '215', '238', '260'],
['Monitor', '410', '452', '498'],
['Printer', '180', '196', '214'],
];
// write the text of every cell row by row and apply the same font
for (let row = 0; row < data.length; row++) {
for (let col = 0; col < data[row].length; col++) {
const cell = table.get_Item(col, row);
cell.TextFrame.Text = data[row][col];
const textRange = cell.TextFrame.Paragraphs.get_Item(0).TextRanges.get_Item(0);
textRange.LatinFont = new pptModule.TextFont('Arial');
}
}
// center the header row and apply a built-in table style
for (let col = 0; col < 4; col++) {
table.get_Item(col, 0).TextFrame.Paragraphs.get_Item(0).Alignment = pptModule.TextAlignmentType.Center;
}
table.StylePreset = pptModule.TableStylePreset.MediumStyle1Accent2;
// save the result file
const outputFileName = 'AddTable_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Working with Tables in PowerPoint</h1>
<button onClick={addTable}>Add a table</button>
</div>
);
}
export default App;
The presentation after adding a table:

Remove the tables from a PowerPoint slide
Tables share the slide's shape collection with text, pictures and other shapes, so removing a shape by index easily hits the wrong element. Walking the collection first, picking out the tables by type into a separate array and then removing them one by one leaves every other shape untouched. A second benefit is that a slide holding several tables is cleaned up in one pass.
| Call | Result |
|---|---|
slide.Shapes.Count |
The number of shapes on the slide |
slide.Shapes.get_Item(index) |
Take a shape on the slide by index |
shape instanceof pptModule.ITable |
Tell whether a shape is a table |
slide.Shapes.Remove(shape) |
Remove the given shape from the slide |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Count, take each shape withShapes.get_Item(i), tell whether it is a table withshape instanceof pptModule.ITable, and put the matches into a separate array. - Walk that array and call
Shapes.Remove()on each table to take it off the slide. - Call
Presentation.SaveToFile()to save the result file andDispose()to release the presentation, then read the file back from the VFS and start the download.
The code that removes the tables from a PowerPoint slide:
function App() {
const removeTable = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the presentation into the VFS
const inputFileName = 'en_Tables.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and collect the tables into a separate array
const tables = [];
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
tables.push(shape);
}
}
// remove each table from the slide
for (let i = 0; i < tables.length; i++) {
slide.Shapes.Remove(tables[i]);
}
// save the result file
const outputFileName = 'RemoveTable_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Working with Tables in PowerPoint</h1>
<button onClick={removeTable}>Remove the table</button>
</div>
);
}
export default App;
The presentation after removing the table from the slide:

FAQ
How do I adjust the column widths and row heights of a table
Cause: The column widths and row heights are given as arrays when the table is inserted, so adjusting a single column or row afterwards means taking the matching object from the row or column collection first.
Solution: ColumnsList and TableRows take a column or row by index (starting from 0); set Width and Height on them, and the overall size of the table follows:
table.ColumnsList.get_Item(1).Width = 220;
table.TableRows.get_Item(1).Height = 60;
How do I center the text vertically inside a cell
Cause: Cell text is anchored to the top by default, so once the row is made taller the text sits against the upper edge and no longer looks centered.
Solution: Set the cell's TextAnchorType to TextAnchorType.Center; use Top or Bottom instead to keep the text at the upper or lower edge:
table.get_Item(col, row).TextAnchorType = pptModule.TextAnchorType.Center;
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.
Set PowerPoint Table Styles and Borders in React
Tables in a slide deck usually have to look consistent from page to page: a filled header row, alternating detail rows, a clear line between every pair of cells. Setting the fills and borders cell by cell takes time as soon as a table grows, and keeping the pages consistent is harder still; switching to another color scheme means redoing the whole table.
This article uses Spire.Presentation for JavaScript to style PowerPoint tables in the browser. The whole process runs locally on the user's device through WebAssembly, requires no Office installation and no back-end service, and keeps the presentation from leaving the browser.
This article covers three features:
- Apply a built-in table style to a PowerPoint table
- Set borders for a PowerPoint table
- Fill the cells of a PowerPoint table
For installation and project configuration, see Integrating Spire.Presentation for JavaScript in a React Project. The examples below assume that Spire.Presentation for JavaScript is installed and the WebAssembly module has been initialized.
Apply a built-in table style to a PowerPoint table
Styling a table from scratch means handling the header row, the total row and the detail rows one at a time; with many rows, the alternating shading easily drifts out of step. A built-in table style packs a complete color scheme into a single preset. Once it is assigned, the fills and text colors of the header row, the total row and the detail rows follow the same set of rules, and the header, total and banding switches decide which rows take part; the rest stay plain.
| What you write | What you get |
|---|---|
shape instanceof pptModule.ITable |
Tells whether a shape is a table |
table.StylePreset = pptModule.TableStylePreset.MediumStyle2Accent3 |
Applies the chosen built-in style to the table |
table.FirstRow = true |
Shows the first row as an emphasized header |
table.LastRow = true |
Shows the last row as an emphasized total row |
table.HorizontalBanding = true |
Shades the detail rows alternately |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Countand find the table withshape instanceof pptModule.ITable. - Set
table.StylePresetto the built-in style you need, then setFirstRow,LastRowandHorizontalBandingtotrueto decide whether the header row, the total row and the alternating shading take effect. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code that applies a built-in table style to a PowerPoint table is as follows:
function App() {
// apply a built-in style to a PowerPoint table
const applyTableStyle = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('simsun.ttc', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableStyle.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// apply a built-in style and turn on the header row, the total row and horizontal banding
table.StylePreset = pptModule.TableStylePreset.MediumStyle2Accent3;
table.FirstRow = true;
table.LastRow = true;
table.HorizontalBanding = true;
// save the result file
const outputFileName = 'ApplyTableStyle_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and start the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Table Styles and Borders in PowerPoint</h1>
<button onClick={applyTableStyle}>Apply a table style</button>
</div>
);
}
export default App;
Presentation after applying a built-in table style:

Set borders for a PowerPoint table
Borders decide where one cell ends and the next begins. Drawing them cell by cell means handling the inner lines as well as the outer edge, and with many rows and columns it is easy to miss one; the divider between the header and the detail rows, on the other hand, often has to stand out from the rest. Borders therefore work at two levels: one call draws every edge of the whole table, and a single edge of a cell can then be set on its own.
| What you write | What you get |
|---|---|
table.SetTableBorder(pptModule.TableBorderType.All, 1.5, pptModule.Color.get_Purple()) |
Sets every edge of the table to the given width and color |
pptModule.TableBorderType.Outside |
Keeps only the outer edge of the table |
pptModule.TableBorderType.Inside |
Keeps only the borders between cells |
pptModule.TableBorderType.None |
Removes the borders of the table |
cell.BorderBottom |
Gets the bottom border of a cell; BorderTop, BorderLeft and BorderRight do the same for the other edges |
cell.BorderBottom.FillType = pptModule.FillFormatType.Solid |
Makes this border a solid line |
cell.BorderBottom.SolidFillColor.Color = pptModule.Color.get_Green() |
Sets the color of this border |
cell.BorderBottom.Width = 3 |
Sets the width of this border, in points |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Countand find the table withshape instanceof pptModule.ITable. - Call
table.SetTableBorder()with the border type, the width in points and the color to draw every edge of the table at once; the color can be taken from the presets ofpptModule.Color. - Walk the columns up to
ColumnsList.Countfor the header row, take each cell withtable.get_Item(col, 0), setcell.BorderBottom.FillTypetoFillFormatType.Solidand giveSolidFillColor.ColorandWidth; this bottom edge then overrides the line drawn at the same place by the table-wide call. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code that sets borders for a PowerPoint table is as follows:
function App() {
// set borders for a PowerPoint table
const setTableBorders = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('simsun.ttc', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableStyle.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// set a 1.5-point purple border on the whole table
table.SetTableBorder(pptModule.TableBorderType.All, 1.5, pptModule.Color.get_Purple());
// add a 3-point green bottom border to every header cell
for (let col = 0; col < table.ColumnsList.Count; col++) {
const cell = table.get_Item(col, 0);
cell.BorderBottom.FillType = pptModule.FillFormatType.Solid;
cell.BorderBottom.SolidFillColor.Color = pptModule.Color.get_Green();
cell.BorderBottom.Width = 3;
}
// save the result file
const outputFileName = 'SetTableBorders_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and start the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Table Styles and Borders in PowerPoint</h1>
<button onClick={setTableBorders}>Set table borders</button>
</div>
);
}
export default App;
Presentation after setting table and cell borders:

Fill the cells of a PowerPoint table
A background color separates the header from the data area, or marks the rows that need attention in a long table. The fill of a cell is managed apart from its borders: set the fill to a solid color, give the color, and the cell stands out from its neighbors. Apply it cell by cell along a row or a few columns and the result is one continuous band, with no gaps in between.
| What you write | What you get |
|---|---|
cell.FillFormat.FillType = pptModule.FillFormatType.Solid |
Makes the fill of the cell a solid color |
cell.FillFormat.SolidColor.Color = pptModule.Color.get_LightBlue() |
Sets the fill color of the cell |
cell.FillFormat.FillType = pptModule.FillFormatType.None |
Removes the fill of the cell |
The steps are:
- Get the Spire.Presentation WASM module and check that it is ready, load the font file and the presentation into the VFS, create a
Presentationobject and load the file withLoadFromFile(), then take the first slide withSlides.get_Item(0). - Walk the shape collection up to
Shapes.Countand find the table withshape instanceof pptModule.ITable. - Walk the columns up to
ColumnsList.Countfor the header row and take each cell withtable.get_Item(col, 0). - Set
cell.FillFormat.FillTypetoFillFormatType.Solid, then give the color withcell.FillFormat.SolidColor.Color. - Save the result with
Presentation.SaveToFile(), release the presentation withDispose(), then read the file from the VFS and start the download.
The code that fills the cells of a PowerPoint table with color is as follows:
function App() {
// fill the cells of a PowerPoint table with color
const fillTableCells = async () => {
// get the Spire.Presentation WASM module
const pptModule = window.wasmModule?.spirepresentation;
// check that the module is ready
if (!pptModule) {
alert('Spire.Presentation is not ready yet');
return;
}
// load the font and the presentation into the VFS
await window.spire.FetchFileToVFS('simsun.ttc', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
const inputFileName = 'en_TableStyle.pptx';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// load the presentation and take its first slide
const ppt = new pptModule.Presentation();
ppt.LoadFromFile(inputFileName);
const slide = ppt.Slides.get_Item(0);
// walk the shape collection and find the table by type
let table = null;
for (let i = 0; i < slide.Shapes.Count; i++) {
const shape = slide.Shapes.get_Item(i);
if (shape instanceof pptModule.ITable) {
table = shape;
break;
}
}
// fill every header cell with light blue
for (let col = 0; col < table.ColumnsList.Count; col++) {
const cell = table.get_Item(col, 0);
cell.FillFormat.FillType = pptModule.FillFormatType.Solid;
cell.FillFormat.SolidColor.Color = pptModule.Color.get_LightBlue();
}
// save the result file
const outputFileName = 'FillCells_result.pptx';
ppt.SaveToFile({ file: outputFileName, fileFormat: pptModule.FileFormat.Pptx2013 });
ppt.Dispose();
// read the generated file from the VFS and start the download
downloadFile(outputFileName);
};
// read the generated file from the VFS and start the download
const downloadFile = (outputFileName) => {
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Table Styles and Borders in PowerPoint</h1>
<button onClick={fillTableCells}>Fill cells</button>
</div>
);
}
export default App;
Presentation after filling the header cells:

FAQ
How can I add only the outer border to a table
Cause: SetTableBorder() handles the whole table according to the border type it receives, and All sets the inner lines together with the outer edge; keeping just the outer edge takes a different border type.
Solution: Pass TableBorderType.Outside instead, with the width and color as usual:
table.SetTableBorder(pptModule.TableBorderType.Outside, 2, pptModule.Color.get_Red());
To keep only the lines between cells, use TableBorderType.Inside.
How do I remove the borders of a table
Cause: Existing borders may come from an earlier version of the template and have to be removed separately.
Solution: Call the method once more with TableBorderType.None and the borders of the whole table are gone:
table.SetTableBorder(pptModule.TableBorderType.None, 1, pptModule.Color.get_Black());
How do I add a diagonal border to a cell
Cause: A diagonal is not one of the four edges of a cell, so members such as BorderTop do not cover it.
Solution: Take it with BorderDiagonalDown or BorderDiagonalUp and set the color and width as for a solid border:
cell.BorderDiagonalDown.FillType = pptModule.FillFormatType.Solid;
cell.BorderDiagonalDown.SolidFillColor.Color = pptModule.Color.get_Red();
cell.BorderDiagonalDown.Width = 2;
Get a Free License
If you wish to delete the evaluation message from the resulting documents, or to get rid of function limitations, please contact sales to obtain a valid 30-day temporary license.