Если вам нужно добавить таблицу в онлайн-документ Word, это может быть сложно сделать программно. Однако, используя следующий API в JavaScript, вы можете автоматически вставить свою таблицу в существующий документ. Вы сможете указать форматирование при вводе запроса на ввод, например цвет затенения ячейки, заливку и узор.
Чтобы начать, вы можете запустить эту команду для установки jQuery:
bower install jquery
Теперь вы готовы ввести URL-адрес редактирования, созданный с помощью функции «Начать редактирование» (см. предыдущую статью на этой неделе), и ваш ключ API в приведенный ниже код для вызова функции:
var settings = { "url": "https://api.cloudmersive.com/convert/edit/docx/insert-table", "method": "POST", "timeout": 0, "headers": { "Content-Type": "application/x-www-form-urlencoded", "Apikey": "YOUR-API-KEY-HERE" }, "data": { "InputFileBytes": "<byte>", "InputFileUrl": "<string>", "TableID": "aliqua id laboris et dolore", "Path": "nulla dolore", "Width": "sunt id ullamco", "WidthType": "ea commodo aliquip anim", "TableRows": "[{\"RowIndex\":50543878,\"Path\":\"Excepteur ea sit\",\"RowCells\":[{\"CellIndex\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Path\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Paragraphs\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingColor\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingFill\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingPattern\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidthMode\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidth\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"}},{\"CellIndex\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Path\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Paragraphs\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingColor\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingFill\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingPattern\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidthMode\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidth\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"}}]},{\"RowIndex\":-83348255,\"Path\":\"officia tempor voluptate eu\",\"RowCells\":[{\"CellIndex\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Path\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Paragraphs\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingColor\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingFill\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingPattern\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidthMode\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidth\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"}},{\"CellIndex\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Path\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"Paragraphs\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingColor\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingFill\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellShadingPattern\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidthMode\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"},\"CellWidth\":{\"value\":\"<Error: Too many levels of nesting to fake this schema>\"}}]}]", "TopBorderType": "ex", "TopBorderSize": "-52157537", "TopBorderSpace": "1293784", "TopBorderColor": "ipsum Lorem", "BottomBorderType": "cillum", "BottomBorderSize": "-80364164", "BottomBorderSpace": "20027988", "BottomBorderColor": "eu dolor veniam culpa", "LeftBorderType": "aliquip ipsum s", "LeftBorderSize": "-45742306", "LeftBorderSpace": "60546058", "LeftBorderColor": "id enim voluptate nostrud in", "RightBorderType": "voluptate Excepteur elit labore", "RightBorderSize": "89079035", "RightBorderSpace": "-97804385", "RightBorderColor": "non Excepteur Lorem sunt labore", "CellHorizontalBorderType": "nisi nostrud proident", "CellHorizontalBorderSize": "8803442", "CellHorizontalBorderSpace": "2988293", "CellHorizontalBorderColor": "qui amet exercitation", "CellVerticalBorderType": "in proident", "CellVerticalBorderSize": "-83125930", "CellVerticalBorderSpace": "54945439", "CellVerticalBorderColor": "ipsum amet", "StartBorderType": "consequat tempor non", "StartBorderSize": "27679945", "StartBorderSpace": "86213006", "StartBorderColor": "consequat nostrud sit", "EndBorderType": "magna anim Ut ut", "EndBorderSize": "-17376836", "EndBorderSpace": "-62097364", "EndBorderColor": "proident", "TableIndentationMode": "ea irure cillum nisi qui", "TableIndentationWidth": "86057474", "InsertPlacement": "<string>", "InsertPath": "<string>" } }; $.ajax(settings).done(function (response) { console.log(response); });
Это упростит редактирование вашего документа, и если у вас больше нет изменений, вы можете вызвать функцию Завершить редактирование, чтобы завершить процесс и загрузить документ. Чтобы получить ключ API, посетите веб-сайт Cloudmersive и зарегистрируйте бесплатную учетную запись; это обеспечивает 800 вызовов в месяц через любой из наших API.