How to Insert a Table in DOCX Using Python

Need to add a new table to your online Word document? We’re here to make inserting your rows and columns of information easier. This helpful process is one of several editing tools you can utilize after opening up editing with our Begin Editing API.

Image for post
Image for post

In order to ensure an accurate output, be sure to input the request configuration:

"InputFileBytes": "string",
"InputFileUrl": "string",
"TableToInsert": {
"TableID": "string",
"Path": "string",
"Width": "string",
"WidthType": "string",
"TableRows": [
"RowIndex": 0,
"Path": "string",
"RowCells": [
"CellIndex": 0,
"Path": "string",
"Paragraphs": [
"ParagraphIndex": 0,
"Path": "string",
"ContentRuns": [
"RunIndex": 0,
"Path": "string",
"TextItems": [
"TextIndex": 0,
"Path": "string",
"TextContent": "string"
"Bold": true,
"Italic": true,
"Underline": "string",
"FontFamily": "string",
"FontSize": "string"
"StyleID": "string"
"CellShadingColor": "string",
"CellShadingFill": "string",
"CellShadingPattern": "string",
"CellWidthMode": "string",
"CellWidth": "string"
"TopBorderType": "string",
"TopBorderSize": 0,
"TopBorderSpace": 0,
"TopBorderColor": "string",
"BottomBorderType": "string",
"BottomBorderSize": 0,
"BottomBorderSpace": 0,
"BottomBorderColor": "string",
"LeftBorderType": "string",
"LeftBorderSize": 0,
"LeftBorderSpace": 0,
"LeftBorderColor": "string",
"RightBorderType": "string",
"RightBorderSize": 0,
"RightBorderSpace": 0,
"RightBorderColor": "string",
"CellHorizontalBorderType": "string",
"CellHorizontalBorderSize": 0,
"CellHorizontalBorderSpace": 0,
"CellHorizontalBorderColor": "string",
"CellVerticalBorderType": "string",
"CellVerticalBorderSize": 0,
"CellVerticalBorderSpace": 0,
"CellVerticalBorderColor": "string",
"StartBorderType": "string",
"StartBorderSize": 0,
"StartBorderSpace": 0,
"StartBorderColor": "string",
"EndBorderType": "string",
"EndBorderSize": 0,
"EndBorderSpace": 0,
"EndBorderColor": "string",
"TableIndentationMode": "string",
"TableIndentationWidth": 0
"InsertPlacement": "string",
"InsertPath": "string"

Next, we can install the SDK by running this command:

pip install cloudmersive-convert-api-client

Once the installation is complete, we’re ready to call the insert table function using the following code:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from import ApiException
from pprint import pprint

And that’s all, folks; this will nestle the new table into your document, as requested. If you have no other editing functions to complete, be sure to run our Finish Editing API to close the operation and download your updated document.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store