The TablesApi interface provided by Spire.Cloud.Word API supports add tables to Word documents, insert rows/ columns into an existing table, delete tables in Word documents and set table format, etc. This article will introduce how to use this API to add table to a Word document.
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TablesApi;
public class AddTable {
private static String appId ="APP ID";
private static String appKey ="APP Key";
private static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a Configuration object based on App ID, App Key and base Url
Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
//Create an instance of TablesApi
TablesApi api = new TablesApi(wordConfiguration);
//Specify the name of the input document
String name = "input.docx";
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Set the position of the table
String nodePath = "Section/0/Body/0";
int indexOfTable = 1;
//Set the number of rows and columns of the table
Integer rowsCount = 6;
Integer columnsCount = 6;
//Specify the storage path and name of the generated document
String destFilePath = "output/AddTable.docx" ;
//Add table to the Word document with the addTable method
api.addTable(name, nodePath, rowsCount, columnsCount, destFilePath, folder, storage, indexOfTable, password );
}
}