DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 34 posts at DZone. View Full User Profile

Split Excel Doc & Save Each Worksheet as PDF, Image at Amazon S3 Storage

02.10.2013
| 3161 views |
  • submit to reddit
//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);
}

This technical tip allows developers 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.