Created
June 8, 2025 13:37
-
-
Save aspose-cloud-kb/ff023244e3ace68f4ad6477f75beaf82 to your computer and use it in GitHub Desktop.
Create an Excel Chart using C# REST API. https://kb.aspose.cloud/cells/net/create-an-excel-chart-using-net-rest-api/
This file contains hidden or 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 Aspose.Cells.Cloud.SDK.Api; | |
using Aspose.Cells.Cloud.SDK.Request; | |
try | |
{ | |
string clientID = "ID"; | |
string clientSecret = "Secret"; | |
string apiBaseUrl = "https://api.aspose.cloud"; | |
CellsApi cellsApi = new CellsApi(clientID, clientSecret, apiBaseUrl); | |
string fileName = "Sample.xlsx"; | |
// Upload file to cloud | |
UploadFileRequest uploadFileRequest = new UploadFileRequest | |
{ | |
path = fileName, | |
storageName = null, | |
UploadFiles = new Dictionary<string, Stream> | |
{ | |
{ fileName, File.OpenRead(fileName) } | |
} | |
}; | |
cellsApi.UploadFile(uploadFileRequest); | |
PutWorksheetChartRequest request = new PutWorksheetChartRequest | |
{ | |
name = fileName, | |
sheetName = "Sheet1", | |
chartType = "pie", | |
upperLeftRow = 5, | |
upperLeftColumn = 5, | |
lowerRightRow = 40, | |
lowerRightColumn = 15, | |
area = "A2:B27", | |
isVertical = true, | |
folder = "" | |
}; | |
cellsApi.PutWorksheetChart(request); | |
var stream = cellsApi.DownloadFile(new DownloadFileRequest() { path = fileName }); | |
string filePath = "output.xlsx"; | |
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) | |
{ | |
stream.CopyTo(fileStream); | |
} | |
Console.WriteLine("Chart Added Successfully"); | |
} | |
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