How to save / extract Excel chart to Image or PDF from in C# using Aspose.Cells REST API

Hi,


I have following questions with regards to Apose Cloud:
We use to extract data from a excel file in various formats. For example: a specific chart or range from an excel document file. Here the input will be an excel file, name of the worksheet containing the data required, name of the chart/range in that worksheet and output format details like image or pdf or html etc… How can we achive this usecase using Aspose cloud REST APIs where we provide the source excel file along with other information(as stated above) and get the desired output in response from that REST request?

Thanks,
Neeraj

Hi,


Thanks for your posting and considering Aspose.Cells for Cloud.

You will have to make use of available Aspose.Cells for Cloud API(s) as found in this link. Please expand the node to see all available API(s).


Please also provide us your sample excel file and the output information which you want to extract from your sample excel file. You can create your sample excel file manually using Microsoft Excel, please keep it as simple as possible. It will give us better picture of your requirement and we will look into it and help you asap.

Thanks for the response.

I was able to get the free trial of Apose cloud after siginng in and able to upload my excel file to Saaspose suceesfully.
However, when I execute the http request like “xxxx://api.aspose.com/v1.1/cells/Loan comparisoncalculator.xlsx/worksheets/Sheet1/charts/1?format=jpeg” I get the error “Access to api.aspose.cloud was denied” even I am alredy logged in through the same browser instance.

Can you please let me know gow to get rid of this issue?

Also let me know till what time the free trial can be used for evalaution?

Thanks,
Neeraj

Hi,


Thanks for your posting and considering Aspose.Cells for Cloud.

Please spare us some time. We will look into this issue and update you asap.

Hi,

Thanks for your posting and considering Aspose.Cells.

Please check the attached sample excel file, I used to test this issue. I have also attached the chart image generated by it for your reference.

Here are the list of methods, GET, POST, PUT, DELETE

For this URL, you will use GET method.

URL:

http://api.aspose.cloud/v1.1/cells/sample.xlsx/worksheets/Sheet1/charts/0?format=jpeg

Check the red parts in the URL. First is workbook name, second is sheet name and 0 means 1st chart.

Please note, in Aspose.Cells, index starts from 0 not from 1. So if you want to get the image of 5th chart, index will be 4 and if you want to get the image of 3rd chart, index will be 2.

Before, you use the GET method with the URL, you must sign the URL with your AppSID and AppKey.

So after signing, the above URL looks like this

Signed URL:

http://api.aspose.cloud/v1.1/cells/sample.xlsx/worksheets/Sheet1/charts/0?format=jpeg&appSID=1d9fc1XXXXXXXXXXXXXXX78620415f&signature=f%2BoTXXXXXXXXXXXXXXX%2BHJw

Now you will use this Signed URL with GET method and it will return you image in JPEG format of the first chart in the Sheet1 of your sample excel file.

**C#**

//Please upload sample.xlsx file in the cloud storage.

string strURI = “http://api.aspose.cloud/v1.1/cells/sample.xlsx/worksheets/Sheet1/charts/0?format=jpeg”;

strURI = Sign(strURI, m_AppSID, m_AppKey);

//Call Process Command with Signed URI

using(Stream responseStream = ProcessCommand(strURI, “Get”))

{

//Save responseStream on disk with .jpg extension

}

@neergupta

Please note, since Aspose.Cells Cloud 19.9 we have introduced a new API Version V3. It uses JSON Web Token(JWT) for API request authentication. Now updated sample cURL and C# code is as follows. Please feel free to contact us for any further assistance.

cURL code:

curl -X GET "https://api.aspose.cloud/v3.0/cells/Book1.xlsx/worksheets/Sheet4/charts/0?format=png&folder=Temp" 
-H "accept: multipart/form-data" 
-H "authorization: Bearer [Access_Token]"
-H "x-aspose-client: Containerize.Swagger"

C# code:

string name = MYDOC;
string sheetName = SHEET3;
int? chartNumber = 0;
string folder = TEMPFOLDER;
string format = "png";

var response = cellsAPI.CellsChartsGetWorksheetChart(name, sheetName, chartNumber, format, folder);