/ Published in: C#
This technical tip shows how developers can split worksheets of an Excel workbook to a separate workbook, TIFF, PNG or any supported image format in the cloud. This example allows you to split all or specific worksheets of a workbook file and save each worksheet as a new workbook, TIFF or any supported image format using Aspose.Cells for Cloud API in your applications. You can use our REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. Some of the code samples are provided for the above languages.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Please take a look over the following code snippet to Split all Worksheets to PNGs [C# Code] AsposeApp.AppSID = "77***********************************"; AsposeApp.AppKey = "9a*******************************"; string outputPath = "C:\\TempFiles\\"; //build URI to split workbook string strURI = "http://api.aspose.com/v1.1/cells/Sample.xlsx/split?format=png"; //sign URI string signedURI = Utils.Sign(strURI); //further process JSON response string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); SplitWorkbookResponse responseStream = JsonConvert.DeserializeObject<SplitWorkbookResponse>(parsedJSON.ToString()); foreach (DocumentResponse splitSheet in responseStream.Result.Documents) { string splitFileName = System.IO.Path.GetFileName(splitSheet.link.Href); //build URI to download split worksheets strURI = "http://api.aspose.com/v1.1/storage/file/" + splitFileName; //sign URI signedURI = Utils.Sign(strURI); //save split worksheets using (Stream fileStream = System.IO.File.OpenWrite(outputPath + splitFileName)) { Utils.CopyStream(Utils.ProcessCommand(signedURI, "GET"), fileStream); } } // class definitions public class SplitWorkbookResponse : Aspose.Cloud.Common.BaseResponse { public SplitWorkbook Result { get; set; } } public class SplitWorkbook { public DocumentResponse[] Documents { get; set; } } public class DocumentResponse { publicint Id { get; set; } public LinkResponse link { get; set; } } /// <summary> /// represents link part of the response /// </summary> public class LinkResponse { public string Href { get; set; } public string Rel { get; set; } public string Title { get; set; } public string Type { get; set; } } Split selected worksheets to TIFFs [C# Code] AsposeApp.AppSID = "77***********************************"; AsposeApp.AppKey = "9a*******************************"; string outputPath = "C:\\TempFiles\\"; //build URI to split workbook string strURI = "http://api.aspose.com/v1.1/cells/Sample.xlsx/split?from=1&to=2&format=tiff"; //sign URI string signedURI = Utils.Sign(strURI); //further process JSON response string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); SplitWorkbookResponse responseStream = JsonConvert.DeserializeObject<SplitWorkbookResponse>(parsedJSON.ToString()); foreach (DocumentResponse splitSheet in responseStream.Result.Documents) { string splitFileName = System.IO.Path.GetFileName(splitSheet.link.Href); //build URI to download split worksheets strURI = "http://api.aspose.com/v1.1/storage/file/" + splitFileName; //sign URI signedURI = Utils.Sign(strURI); //save split worksheets using (Stream fileStream = System.IO.File.OpenWrite(outputPath + splitFileName)) { Utils.CopyStream(Utils.ProcessCommand(signedURI, "GET"), fileStream); } } // class definitions public class SplitWorkbookResponse : Aspose.Cloud.Common.BaseResponse { public SplitWorkbook Result { get; set; } } public class SplitWorkbook { public DocumentResponse[] Documents { get; set; } } public class DocumentResponse { publicint Id { get; set; } public LinkResponse link { get; set; } } /// <summary> /// represents link part of the response /// </summary> public class LinkResponse { public string Href { get; set; } public string Rel { get; set; } public string Title { get; set; } public string Type { get; set; } }
URL: http://www.aspose.com/docs/display/cellscloud/Split+Excel+Workbooks