Skip to content

Instantly share code, notes, and snippets.

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