Home > Code > C# > Split Worksheets of an Excel Workbook to TIFF or PNG Using C# in Cloud

Split Worksheets of an Excel Workbook to TIFF or PNG Using C# in Cloud

by sher azam   on Feb 11, 2014   Category: C#   |  Views: 1019    |  Points: 25   |  Gold 


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.

Please take a look over the following code snippet for Split all Worksheets to PNGs

[C#]

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);
StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "POST"));
//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
{
public int 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);
StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "POST"));
//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
{
public int 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; }
}

More about Aspose.Cells for Cloud

- Homepage of Aspose.Cells for Cloud: http://www.aspose.com/cloud/excel-api.aspx

- Read More Technical Tips by Aspose.Cells for Cloud: http://www.aspose.com/docs/display/cellscloud/Working+with+Workbook



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts