Last active
April 14, 2024 14:29
Create Table in Word with NET REST API. https://kb.aspose.cloud/words/net/create-table-in-word-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using Aspose.Words.Cloud.Sdk; | |
using Aspose.Words.Cloud.Sdk.Model; | |
using Aspose.Words.Cloud.Sdk.Model.Requests; | |
namespace WordsSample.Words | |
{ | |
public class WordFileOperations | |
{ | |
public void CreateTable() | |
{ | |
try | |
{ | |
var wordsApi = new WordsApi("", ""); | |
using var requestDocument = File.OpenRead("Sample.docx"); | |
var requestTable = new TableInsert() | |
{ | |
ColumnsCount = 5, | |
RowsCount = 4 | |
}; | |
string output = "OutputWithTable.docx"; | |
var insertRequest = new InsertTableOnlineRequest(requestDocument, requestTable, destFileName: output); | |
var tableTask = wordsApi.InsertTableOnline(insertRequest); | |
tableTask.Wait(); | |
var result = tableTask.Result; | |
if (result.Document.TryGetValue(output, out var stream)) | |
{ | |
stream.Position = 0; | |
using (var fileStream = File.Create(output)) | |
{ | |
stream.Seek(0, SeekOrigin.Begin); | |
stream.CopyTo(fileStream); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment