Hi,
Thanks for using Aspose.Cells.
Please see the following PHP code for using Aspose.Cells for Cloud Calculate Formula feature.
I have attached the TestCalculateFormula.php which tests Calculate Formula.
I have also attached the source.xlsx file which contains
A1: 100
A2: 100
A3: =Sum(A1:A2) //200
First, the code uploads source.xlsx file on Cloud, then it sets the value of cell A1 to 500, then it reads the value of cell A3, which is still 200 and then it calculates the formula and reads the value of cell A3 again, this time its gives correct value that is 600.
A1: 500
A2: 100
A3: =Sum(A1:A2) //600
I have also attached the full Virtual Directory which also contains Aspose PHP Cloud SDK for your ease.
PHP
<?php
require '/Aspose/Cloud/Common/AsposeApp.php';
require '/Aspose/Cloud/Exception/AsposeCloudException.php';
require '/Aspose/Cloud/Common/Utils.php';
require '/Aspose/Cloud/Storage/Folder.php';
use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Utils;
//Test Calculate Formula
TestCalculateFormula();
function TestCalculateFormula()
{
AsposeApp::$appSID = "xxxxxx-xxxxx-xxxxx-xxxxx-xxxxxx";
AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
//Upload the source file with the formula
UploadFile(getcwd() . "\\source.xlsx");
//Set cell A1 as 500
SetCellValue("source.xlsx", "Sheet1", "A1", "500", "int");
//Read the cell A3 value before CalculateFormula
GetCellValue("source.xlsx", "Sheet1", "A3");
//Calculate the formulas
CalculateFormula("source.xlsx");
//Read the cell A3 value after CalculateFormula
GetCellValue("source.xlsx", "Sheet1", "A3");
}
function UploadFile($filePath)
{
$fileName = basename($filePath);
$URIRequest = "http://api.aspose.com/v1.1/storage/file/" . $fileName;
$URISigned = Utils::Sign($URIRequest);
$check = Utils::uploadFileBinary($URISigned, $filePath);
}
function DownloadFile($fileName, $outputPath)
{
$strURI = "http://api.aspose.com/v1.1/storage/file/" . $fileName;
$signedURI = Utils::Sign($strURI);
$responseStream = Utils::processCommand($signedURI, "GET", "", "");
Utils::saveFile($responseStream, getcwd() . "/" . $outputPath);
}
function SetCellValue($workbookName, $worksheetName, $cellName, $cellValue, $cellType)
{
$strURI = "http://api.aspose.com/v1.1/cells/" . $workbookName . "/worksheets/" . $worksheetName . "/cells/"
. $cellName . "?value=" . $cellValue . "&type=" . $cellType;
$signedURI = Utils::Sign($strURI);
$responseStream = Utils::processCommand($signedURI, "POST", "", "");
echo "\r\nResponseStream After Setting Cell Value: \r\n" . $responseStream . "\r\n\r\n";
}
function GetCellValue($workbookName, $worksheetName, $cellName)
{
$strURI = "http://api.aspose.com/v1.1/cells/" . $workbookName . "/worksheets/" . $worksheetName . "/cells/" . $cellName;
$signedURI = Utils::Sign($strURI);
$responseStream = Utils::processCommand($signedURI, "GET", "", "");
echo "\r\nResponseStream After Getting Cell Value: \r\n" . $responseStream . "\r\n\r\n";
}
function CalculateFormula($workbookName)
{
$strURI = "http://api.aspose.com/v1.1/cells/" . $workbookName . "/CalculateFormula";
$signedURI = Utils::Sign($strURI);
$responseStream = Utils::processCommand($signedURI, "POST", "", "");
echo "\r\nResponseStream After Workbook CalculateFormula: \r\n" . $responseStream . "\r\n\r\n";
}
?>
Echo Output:ResponseStream After Setting Cell Value:
{"Cell":{"Name":"A1","Row":0,"Column":0,"Value":"500","Type":"IsNumeric","Formula":null,"IsFormula":false,"IsMerged":false,"IsArrayHeader":false,"IsInArray":false,"IsErrorValue":false,"IsInTable":false,"IsStyleSet":false,"HtmlString":"500","Style":{"link":{"Href":"/style","Rel":"self","Type":null,"Title":null}},"Worksheet":null,"link":{"Href":"http://api.aspose.com/v1.1/cells/source.xlsx/worksheets/Sheet1/cells/A1","Rel":"self","Type":null,"Title":null}},"Code":200,"Status":"OK"}
ResponseStream After Getting Cell Value:
{"Cell":{"Name":"A3","Row":2,"Column":0,"Value":"200","Type":"IsNumeric","Formula":"=SUM(A1:A2)","IsFormula":true,"IsMerged":false,"IsArrayHeader":false,"IsInArray":false,"IsErrorValue":false,"IsInTable":false,"IsStyleSet":false,"HtmlString":"200","Style":{"link":{"Href":"/style","Rel":"self","Type":null,"Title":null}},"Worksheet":null,"link":{"Href":"http://api.aspose.com/v1.1/cells/source.xlsx/worksheets/Sheet1/cells/A3","Rel":"self","Type":null,"Title":null}},"Code":200,"Status":"OK"}
ResponseStream After Workbook CalculateFormula:
{"Code":200,"Status":"OK"}
ResponseStream After Getting Cell Value:
{"Cell":{"Name":"A3","Row":2,"Column":0,"Value":"600","Type":"IsNumeric","Formula":"=SUM(A1:A2)","IsFormula":true,"IsMerged":false,"IsArrayHeader":false,"IsInArray":false,"IsErrorValue":false,"IsInTable":false,"IsStyleSet":false,"HtmlString":"600","Style":{"link":{"Href":"/style","Rel":"self","Type":null,"Title":null}},"Worksheet":null,"link":{"Href":"http://api.aspose.com/v1.1/cells/source.xlsx/worksheets/Sheet1/cells/A3","Rel":"self","Type":null,"Title":null}},"Code":200,"Status":"OK"}