Import Data to Excel Worksheet via PHP using Aspose.Cells Rest API

Hello,

I’m sorry to reopen the topic but I think the documentation is not 100%. By the way i’m newbie at ASPOSE and APIs.

In the GITHUB Cells Documentation says:
"

Import Data to Excel Worksheet via PHP

require_once realpath(DIR . ‘/…’) . ‘/vendor/autoload.php’;
require_once realpath(DIR . ‘/…’) . ‘/Utils.php’;
use Aspose\Cells\CellsApi;
use Aspose\Cells\AsposeApp;
"

I think it’s not correct because I cannot find Utils anywhere.

@ovgp,
Yes, you are correct.
We will fix it.

Thanks for the fast answer.

As I mentioned before I’m newbie at API and Aspose and I need help or an example. I’m sorry for that.

I was on GitHub - aspose-cells-cloud/aspose-cells-cloud-php: PHP SDK to communicate with Aspose.Cells REST API. Create, Edit & Convert Excel files in the Cloud. and I did the following:

  1. I had Installed XAMPP (with PHP 8)
  2. I had installed Composer 2.0.14
  3. I create the following folder: C:\xampp\htdocs\intranet\testes\aspose
  4. At command line (as administrator) in that folder I run: composer require aspose/storage-sdk-php
  5. At command line (as administrator) in that folder I run: composer require aspose/cells-sdk-php

At C:\xampp\htdocs\intranet\testes\aspose\test_git.php with the example code:

<?php require_once('vendor/autoload.php'); //I replaced: require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php'; use Aspose\Cells\CellsApi; use Aspose\Cells\AsposeApp; class Workbook { public $cells; public function __construct() { AsposeApp::$clientId = Utils::clientId; AsposeApp::$clientSecret = Utils::clientSecret; $this->cells = new CellsApi( AsposeApp::$clientId,AsposeApp::$clientSecret ); } public function postImportDataCloudFile() { $name ='Book1.xlsx'; $folder = "PhpTest"; $data = new ImportIntArrayOption(); $data->setDestinationWorksheet('Sheet1'); $data->setFirstColumn(1); $data->setFirstRow(3); $data->setImportDataType('IntArray'); $data->setIsVertical('true'); $data->setData(array(1, 2, 3, 4)) ; $this->instance->uploadFile($folder + "/" + $name , $sourceFolder + $name); $result = $this->instance->cellsWorkbookPostImportData($name, $data, $folder); } } $workbook = new Workbook(); $workbook->postImportDataCloudFile(); ?>

It gives me an error saying:
Fatal error : Uncaught Error: Class “Utils” not found in C:\xampp\htdocs\intranet\testes\aspose\test_git.php:13 Stack trace: #0 C:\xampp\htdocs\intranet\testes\aspose\test_git.php(34): Workbook->__construct() #1 {main} thrown in C:\xampp\htdocs\intranet\testes\aspose\test_git.php on line 13

NOTES:
I don’t know where to put the credentials “Client ID” and “Client Secret”.

Can you help me please? Or maybe you can gives me an example?

Thanks in advance

@ovgp,

You need to log in https://dashboard.aspose.cloud/ and get your Client Id and Client Secret from Applications.
image.png (29.4 KB)

Please check php-sdk-examples code.
php-sdk-examples.zip (109.4 KB)

@wangtao
Thanks for the answer.
I used your example and I get the following error:
image.png (40.1 KB)

The only change I made was change the $sourceFolder:
//$sourceFolder = “D:\projects\aspose\aspose.cells.cloud.sdk\examples\php-sdk-examples\”;
$sourceFolder = “C:\xampp\htdocs\intranet\testes\aspose\”;

This is my tree of files:
image.png (12.4 KB)
image.png (6.8 KB)

I’ve got the Client Credentials (ClientID + ClientSecret) but I don’t know which file of PHP I should put it.

Can you help?

Thanks in advance,
Ricardo Silva

@ovgp,

Please try to put your client id and client secret directly, and use the following code to create a new CellsApi.

$this->cells = new CellsApi('your client id','your client secret','v3.0','https://api.aspose.cloud/');

And note windows escape character .

$sourceFolder = “C:\\xampp\\htdocs\\intranet\\testes\\aspose\\”;

@wangtao

Works like a charm.

Just an opinion from a newbie guy, I think you should update the documentation, at least in the main page ( GitHub - aspose-cells-cloud/aspose-cells-cloud-php: PHP SDK to communicate with Aspose.Cells REST API. Create, Edit & Convert Excel files in the Cloud. ), explaining where to put the ClientID and ClientSecret.

In fact, that line:
$this->cells = new CellsApi(‘your client id’,‘your client secret’,‘v3.0’,‘https://api.aspose.cloud/’);
made the all difference for me.

Just an opinion.

Thank you so much.

Another difficult that I have is about obsolete documentation.
For example, in the page SaveAs Excel|Aspose.Cells Cloud Document I use the example shown on PHP separator and I’ve got the error on the line:
CellsApiTestBase::ready( $this->instance,$name ,$folder);

Maybe it’s because AsposeApp is not present on SDK.

How to work around?

Thanks in advance.

@ovgp,

We have fixed the sample code for the API for saving as and importing data.
We will improve the online document as soon as possible.