Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-cloud-kb/ec6422f920cb0e63767b06978438d029 to your computer and use it in GitHub Desktop.
Save aspose-cloud-kb/ec6422f920cb0e63767b06978438d029 to your computer and use it in GitHub Desktop.
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Request;
class ExcelChartExporter
{
static void Main()
{
try
{
// Initialize API credentials and endpoint
string appKey = "Application Key";
string appSecret = "Application Secret";
string serviceBaseUrl = "https://api.aspose.cloud";
// Create an instance of the Aspose.Cells API client
CellsApi cellsClient = new CellsApi(appKey, appSecret, serviceBaseUrl);
// Define local Excel file path
string spreadsheetFile = "charts.xlsx";
// Prepare and execute file upload request
var fileUpload = new UploadFileRequest
{
path = spreadsheetFile,
UploadFiles = new Dictionary<string, Stream>
{
{ spreadsheetFile, File.OpenRead(spreadsheetFile) }
}
};
cellsClient.UploadFile(fileUpload);
// Setup parameters for exporting chart as an image
var chartExportRequest = new GetWorksheetChartRequest
{
name = spreadsheetFile,
sheetName = "Sheet1",
chartNumber = 0,
folder = "", // Root folder
format = "PNG", // Export format
storageName = "" // Default storage
};
// Fetch the chart image stream from the API
var chartImageStream = cellsClient.GetWorksheetChart(chartExportRequest);
// Save the image stream to a file
string chartImageOutput = "chart_output.png";
using (FileStream outputFileStream = new FileStream(chartImageOutput, FileMode.Create, FileAccess.Write))
{
chartImageStream.CopyTo(outputFileStream);
}
Console.WriteLine("The chart has been successfully converted to an image.");
}
catch (Exception error)
{
Console.WriteLine("Something went wrong: " + error.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment