C# and VB.NET Code to Split Worksheets of an Excel Workbook to TIFF or PNG in Cloud
This technical tip shows how developers can split worksheets of a 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 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);
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; }
}
[VB.NET]
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
- Download Aspose.Cells for Cloud SDKs
- More Technical Tips by Aspose.Cells for Cloud