Sunday, February 10, 2013

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

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.
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);
}
Overview: Saaspose.Cells
Saaspose.Cells is a REST API for processing spreadsheets in the cloud. It allows creating, manipulating & converting spreadsheets in web, desktop, mobile & cloud applications. It supports rows, columns, cells, text, data, images, hyperlinks, comments, formulas & many other aspects of spreadsheets. It can be used with any language to incorporate the spreadsheet processing features in any type of business application. It renders spreadsheets & charts to images like JPEG, PNG, SVG, GIF or TIFF etc.
More about Saaspose.Cells
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465

No comments:

Post a Comment