How to get a specific table by index in a Word DOCX document in Node.JS
1 min readMay 16, 2020
For today’s example, we will be looking at how to use Node.JS to obtain a specific table from a DOCX file using its index number. To avoid any possibility of hardship, we will apply an API to the problem at hand, allowing us to finish the whole thing in mere minutes.
Our API will need its client installed:
npm install cloudmersive-convert-api-client --save
Calling editDocumentDocxGetTableByIndex can be done through an API instance, as you can see in this block of code here:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditDocumentApi();var reqConfig = new CloudmersiveConvertApiClient.GetDocxTableByIndexRequest(); // GetDocxTableByIndexRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentDocxGetTableByIndex(reqConfig, callback);
And we’re done! Talk about easy. For more useful functions like this, take a look at the rest of this same library.