I’m using Aspose.Cells for Cloud with the C# SDK, and have tried several of the ImportData examples without success.
I have uploaded a simple Array_int_json.txt
file containing “[1,2,3]” to my Aspose Cloud folder.
I then try to import them to my Excel file:
string options2 = "{\"FirstRow\":1,\"FirstColumn\":2,\"IsVertical\":true,\"Data\":null,\"DestinationWorksheet\":\"Testings\",\"IsInsert\":true,\"ImportDataType\":\"IntArray\",\"Source\":{\"FileSourceType\":1,\"FilePath\":\"Array_int_json.txt\"}}";
try
{
string sheet = "Testings";
cellsApi.PutAddNewWorksheet(filename, sheet, storage, folder);
SaaSposeResponse apiResponse = cellsApi.PostImportData(filename, storage, folder, options2);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
This gives an exception with a bad request error code 400.
In the API usage log, I can see the following message:
Error: The best overloaded method match for 'Aspose.Cells.Cloud.Common.Converters.ImportOptionConverter.ReadFromJson(System.Type, Newtonsoft.Json.Linq.JObject)' has some invalid arguments. Method: Import data (array) to workbook worksheet.. Parameters: name 'My_Test.xlsx',folder ''
I have tried the other examples in “https://docs.aspose.com/display/cellscloud/Import+Data+into+Worksheet” with the same result.
@morten_ok
Thanks for using Aspose APIs.
Please spare us some time. We will look into this issue and help you asap.
@morten_ok
Please try the following code and read its comments. I have attached the sample Excel file used in this code and output Excel file generated by the code for your reference.
C#
//Please upload sample.xlsx file in the cloud storage.
//Sign ImportData API with your AppSID and AppKey
string strURI = "http://api.aspose.com/v1.1/cells/sample.xlsx/importdata";
strURI = Sign(strURI, m_AppSID, m_AppKey);
//XML body that imports integers into worksheet
//Import 5 integers in Sheet1 starting from cell A3 vertically. You can also set IsVertical to false to import them horizontally.
string xmlBody = @"
<ImportIntArrayOption>
<DestinationWorksheet>Sheet1</DestinationWorksheet>
<FirstRow>2</FirstRow>
<FirstColumn>0</FirstColumn>
<IsInsert>false</IsInsert>
<IsVertical>true</IsVertical>
<Data>
<int>20</int>
<int>30</int>
<int>40</int>
<int>50</int>
<int>100</int>
</Data>
</ImportIntArrayOption>";
//Call Process Command with Signed URI
Stream responseStream = ProcessCommand(strURI, "POST", xmlBody, "XML");
//Convert response stream into string
//Please download sample.xlsx file from the cloud storage.
Thank you for your response.
I don’t have access to Sign()
or ProcessCommand()
using the CellsApi or the StorageApi.
I have tried to import the xmlBody
you provided using CellsApi.PostImportData()
:
CellsApi cellsApi = new CellsApi(appKey, appSid, basePath);
StorageApi storageApi = new StorageApi(appKey, appSid, basePath);
//Create a new Workbook - has a default sheet called "Sheet1"
string filename = "Testings.xlsx";
try
{
cellsApi.PutWorkbookCreate(filename, null, null, null, null, null);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
string xmlBody = @"
<ImportIntArrayOption>
<DestinationWorksheet>Sheet1</DestinationWorksheet>
<FirstRow>2</FirstRow>
<FirstColumn>0</FirstColumn>
<IsInsert>false</IsInsert>
<IsVertical>true</IsVertical>
<Data>
<int>20</int>
<int>30</int>
<int>40</int>
<int>50</int>
<int>100</int>
</Data>
</ImportIntArrayOption>";
try
{
cellsApi.PostImportData(filename, null, null, xmlBody);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
This gives me the same error as before:
Error: The best overloaded method match for 'Aspose.Cells.Cloud.Common.Converters.ImportOptionConverter.ReadFromJson(System.Type, Newtonsoft.Json.Linq.JObject)' has some invalid arguments. Method: Import data (array) to workbook worksheet.. Parameters: name 'Testings.xlsx',folder ''
It could be a problem with the C# SDK. Maybe it can only handle correctly formatted JSON body.
Do you have a small example on how the JSON should be structured for importing values to several cells?
@morten_ok
It seems to be SDK problem. I have created a test project that you can download and run instantly by pressing F5.
1 - First upload Input Excel file manually
2 - Run the test project.
3 - Download the Output Excel file manually. Output Excel file is actually the Input Excel file but it is now modified by Aspose.Cells for Cloud Test Project.
@shakeel.faiz Thank you. It works.
It also works using JSON and setting the content type:
request.ContentType = "application/json"
Then I can POST a Data integer array directly (without first uploading a data file):
string options2 = "{\"FirstRow\":1,\"FirstColumn\":2,\"IsVertical\":true,\"Data\":[1,2,42],\"DestinationWorksheet\":\"Sheet1\",\"IsInsert\":false,\"ImportDataType\":\"IntArray\"}";
I can also POST a BatchData JSON structure directly:
string options0 = "{\"BatchData\":[{\"rowIndex\":0,\"columnIndex\":0,\"type\":\"String\",\"value\":\"sport\",\"style\":null},{\"rowIndex\":0,\"columnIndex\":1,\"type\":\"String\",\"value\":\"ultra\",\"style\":null}],\"DestinationWorksheet\":\"Sheet1\",\"IsInsert\":false,\"ImportDataType\":\"BatchData\"}";
Nice.
The examples above are missing in the documentation. The JSON structure should also be better documented.
The CellsApi.PostImportData()
appears broken in the C# SDK.
@morten_ok
Thanks for your good news and using Aspose APIs.
Most of these issues are already being fixed by Cloud Team. We will look into your issue further and report it to Cloud Team.
In the meanwhile, if you need any help, please feel free to ask or create newer threads/posts. We will help you asap.