Cloudmersive

Aug 19, 2021

1 min read

Insert a Table into an Online DOCX File in C/C++

Employing data tables in your documents can assist in providing a clear visual display of the information. By running this API in C/C++, you can instantly add a new table to an online Word document. You will need to call the Begin Editing function (detailed in an article last week) first to retrieve the editing URL, which you can then input into the example code provided in this tutorial.

To begin the process, you will need to install libcurl into your C/C++ project:

libcurl/7.75.0

With the installation out of the way, we can call the Insert Table function with the following code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/edit/docx/insert-table");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "InputFileBytes=%3Cbyte%3E&InputFileUrl=%3Cstring%3E&TableID=ipsum%20o&Path=in%20a&Width=dolore&WidthType=ipsum%20labore&TableRows=%5B%7B%22RowIndex%22%3A-68485824%2C%22Path%22%3A%22ea%22%2C%22RowCells%22%3A%5B%7B%22CellIndex%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Path%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Paragraphs%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingColor%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingFill%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingPattern%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidthMode%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidth%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%7D%2C%7B%22CellIndex%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Path%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Paragraphs%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingColor%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingFill%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingPattern%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidthMode%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidth%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%7D%5D%7D%2C%7B%22RowIndex%22%3A1896906%2C%22Path%22%3A%22enim%22%2C%22RowCells%22%3A%5B%7B%22CellIndex%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Path%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Paragraphs%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingColor%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingFill%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingPattern%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidthMode%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidth%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%7D%2C%7B%22CellIndex%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Path%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22Paragraphs%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingColor%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingFill%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellShadingPattern%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidthMode%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%2C%22CellWidth%22%3A%7B%22value%22%3A%22%3CError%3A%20Too%20many%20levels%20of%20nesting%20to%20fake%20this%20schema%3E%22%7D%7D%5D%7D%5D&TopBorderType=occaecat%20tempor%20minim&TopBorderSize=92176803&TopBorderSpace=-82878052&TopBorderColor=incididunt%20est%20id%20in%20anim&BottomBorderType=eu%20minim%20incididunt&BottomBorderSize=-13577321&BottomBorderSpace=-66019760&BottomBorderColor=pari&LeftBorderType=esse%20aliquip%20ea&LeftBorderSize=68506178&LeftBorderSpace=-63984894&LeftBorderColor=consectetur%20proident%20ipsum%20esse%20aliqua&RightBorderType=incididunt%20qui&RightBorderSize=-41151400&RightBorderSpace=-69696469&RightBorderColor=est%20culpa%20dolor%20aute%20non&CellHorizontalBorderType=occaecat%20laborum%20pariatur&CellHorizontalBorderSize=-16478298&CellHorizontalBorderSpace=-63090640&CellHorizontalBorderColor=dolore%20in%20aute&CellVerticalBorderType=dolor%20ullamco&CellVerticalBorderSize=-8756623&CellVerticalBorderSpace=-62376751&CellVerticalBorderColor=sit%20quis&StartBorderType=fugiat%20exercitation&StartBorderSize=29001604&StartBorderSpace=-43780251&StartBorderColor=Ut%20aute%20incididunt&EndBorderType=ut%20aute%20laborum&EndBorderSize=-4647052&EndBorderSpace=29504951&EndBorderColor=esse&TableIndentationMode=pariatur%20quis%20esse&TableIndentationWidth=24088640&InsertPlacement=%3Cstring%3E&InsertPath=%3Cstring%3E";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);

Once your editing is complete, you can call Finish Editing on the output URL to close out the operation.