0
Answer

Split Excel into New Workbooks using Cloud API in Ruby

Cloud Developers can now use ruby language to split excel workbook into single worksheets and save all or specific worksheets as new workbooks, TIFFs or other images format by using Aspose.Cells for Cloud API. To split workbooks, you need to upload the input Excel files to Aspose for Cloud or any supported third party storage and then send a POST request to the Aspose for Cloud service.

 

The following REST example uses the RestClient library to send HTTP requests and handle HTTP responses so you need to install RestClient to use these examples. You can use the following URI to split a workbook on Aspose for Cloud or any supported third party storage.

 

http://api.aspose.com/v1.1/cells/Sample.xlsx/split?format=png

 

Use following optional parameters with the above URI. All or specific parameters can be used according to your requirement. If no parameter is specified, then all worksheets are split to the specified format.

 

  • storage – Used to set the storage name if you are using third party storage.
  • folder – Used to set the name and path of the folder where the input file has been uploaded.
  • from – Used to set the start page number if you are splitting specific pages.
  • to – Used to set the end page number if you are splitting specific pages.

 

After building the URI:

 

  1. Set the App SID and App Key and sign the URI.

            See section 1 of the code and the Sign URI method for more details.

  1. Send a POST request to the Aspose for Cloud service.

            See section 2 of the code for more details.

 

Following is the code to split Excel to new workbooks


#######

Section 1 ######

app_sid = '####### Section 1 ######

app_sid = '77******-1***-4***-a***-80**********'

app_key = '*********************'

Aspose::Cloud::Common::AsposeApp.new(app_sid, app_key)

#build URI to split workbook

str_uri = 'http://api.aspose.com/v1.1/cells/Sample.xlsx/split?format=png';

#uncomment following line to split specific worksheets

#str_uri = 'http://api.aspose.com/v1.1/cells/Sample.xlsx/split?from=2&to=3&format=tiff';

#sign URI

signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri);

#######

End Section 1 ######

#######

Section 2 ######

#Split spreadsheet file

response_stream = RestClient.post(signed_uri, '', {:accept=>:json})

#######

End Section 2 #####

 

#Download Split Files

 

stream_hash = JSON.parse(response_stream)

stream_hash['Result']['Documents'].each do |document|

 

       #Build and sign URI to download split files

 

file_name = File.basename(document['link']['Href'])

str_uri = 'http://api.aspose.com/v1.1/storage/file/' + file_name;            

signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri);

 

file_name = File.basename(str_uri)

 

      #Download and save split files

 

response_stream = RestClient.get(signed_uri, :accept => 'application/json')

      Aspose::Cloud::Common::Utils.save_file(response_stream, file_name)

 

End