PHP Code to Split Excel Document & Save it as PDF or Image etc and use it in App

This technical tip allows developers how to split all or specific pages of an Excel document and save each worksheet as PDF, Image or any supported format using Saaspose.Cells REST API in your PHP applications. Input Excel documents need to be uploaded at Amazon S3 Storage before running this code. You need to configure Amazon S3 Storage with Saaspose before using this example. Some important steps for performing this task are to build URI to split sheets, sign URI, iterate through each document in the result to find output sheets,build URI to download split sheets And save split PDF pages.

Sample Code for Splitting Excel Documents at Amazon S3 Storage


SaasposeApp::$AppSID  = "77***********************************";
SaasposeApp::$AppKey = "9a*******************************";
SaasposeApp::$OutPutLocation = getcwd() . "\\Output\\";

$AmazonS3StorageName = "AmazonS3Storage";
$AmazonS3BucketName = "Saaspose";
$AmazonS3Folder = $AmazonS3BucketName . "/Folder1"; // use $AmazonS3Folder = $AmazonS3BucketName for root folder

//build URI to split sheets
$strURI = 'http://api.saaspose.com/v1.0/cells/Sample1.xlsx/split?format=png&storage=' . $AmazonS3StorageName . '&folder=' . $AmazonS3Folder; 

//sign URI
$signedURI = Utils::Sign($strURI);

$responseStream = Utils::processCommand($signedURI, "POST", "", "");
$json = json_decode($responseStream);

//iterate throug each document in the result to find output sheets
foreach ($json->Result->Documents as $splitSheet) { 
	$splitFileName = $splitSheet->link->Href;
	
	//build URI to download split sheets 
	$strURI = 'http://api.saaspose.com/v1.0/storage/file/'. $AmazonS3Folder . '/' . $splitFileName .'?storage=' . $AmazonS3StorageName;
	
	//sign URI
	$signedURI = Utils::Sign($strURI);

	$responseStream = Utils::processCommand($signedURI, "GET", "", "");
	//save split PDF pages
	$outputFile = SaasposeApp::$OutPutLocation . $splitFileName;
	Utils::saveFile($responseStream, $outputFile);
}
Sponsor our Newsletter | Privacy Policy | Terms of Service