asposecellsjava 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbaa278efed46b4db09f23bae691ff0cda98c031
4
+ data.tar.gz: f9fdba855bb7035d44b43c3e7965e48b6a148acd
5
+ SHA512:
6
+ metadata.gz: eb4d7ee8d45c705e8e7ffebe2574b506775fb6fbd7e3ccc9c3e111ee9ac91766c3160971a482ffb1cdba33d58ba1117dbce17a2dc80c6a116baddaccd316ba1d
7
+ data.tar.gz: 60206355c79e7fbfd3c4cc9cace000b31cd8744c2e56708b20e29e076bf3bb5a375037238dd5aa7a3d6ac9b11a1a44d87b82b48ef559e85bebfd9a87665913fa
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2001-2015 Aspose Pty Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Aspose_Cells_Java_For_Ruby
2
+ Aspose Cells Java for Ruby is a gem that demonstrates / provides the Aspose.Cells for Java API usage examples in Ruby by using Rjb - Ruby Java Bridge.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'asposecellsjava'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install asposecellsjava
19
+
20
+ To download Aspose.Cells for Java API to be used with these examples through RJB, Please navigate to:
21
+
22
+ http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/
23
+
24
+ For most complete documentation of the project, check Aspose.Cells Java for Ruby confluence wiki link:
25
+
26
+ http://www.aspose.com/docs/display/cellssjava/3.+Aspose.Cells+Java+For+Ruby
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require '../lib/asposecellsjava'
32
+ include Asposecellsjava
33
+ include Asposecellsjava::HideUnhideWorksheet
34
+ initialize_aspose_cells
35
+ ```
36
+ Lets understand the above code
37
+ * The first line makes sure that the aspose cells is loaded and available
38
+ * Include the files that are required to access the aspose cells
39
+ * Initialize the libraries. The aspose JAVA classes are loaded from the path provided in the aspose.yml file
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asposecellsjava/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'asposecellsjava'
8
+ spec.version = Asposecellsjava::VERSION
9
+ spec.authors = ['Aspose Marketplace']
10
+ spec.email = ['marketplace@aspose.com']
11
+ spec.summary = %q{A Ruby gem to work with aspose.cells libraries}
12
+ spec.description = %q{AsposeCellsJava is a Ruby gem that can help working with Aspose.Cells libraries}
13
+ spec.homepage = 'https://github.com/asposecells/Aspose_Cells_Java/tree/master/Plugins/Aspose_Cells_Java_for_Ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+
25
+ spec.add_dependency 'rjb', '~> 1.5.2'
26
+
27
+ end
data/config/aspose.yml ADDED
@@ -0,0 +1,5 @@
1
+ jar_dir: ../asposecellsjava/jars
2
+ license_path: ../asposecellsjava/license/path
3
+ jvm_args: -Xms512m -Xmx1G
4
+
5
+
data/data/Book1.xls ADDED
Binary file
data/data/index.html ADDED
@@ -0,0 +1,26 @@
1
+ <html>
2
+ <head>
3
+ <title>Sample "Hello, World" Application</title>
4
+ </head>
5
+ <body bgcolor=white>
6
+
7
+ <table border="0" cellpadding="10">
8
+ <tr>
9
+ <td>
10
+ <img src="images/springsource.png">
11
+ </td>
12
+ <td>
13
+ <h1>Sample "Hello, World" Application</h1>
14
+ </td>
15
+ </tr>
16
+ </table>
17
+
18
+ <p>This is the home page for the HelloWorld Web application. </p>
19
+ <p>To prove that they work, you can execute either of the following links:
20
+ <ul>
21
+ <li>To a <a href="hello.jsp">JSP page</a>.
22
+ <li>To a <a href="hello">servlet</a>.
23
+ </ul>
24
+
25
+ </body>
26
+ </html>
@@ -0,0 +1,71 @@
1
+ require_relative 'asposecellsjava/version'
2
+ require_relative 'asposecellsjava/asposecells'
3
+ require 'logger'
4
+ require 'rjb'
5
+
6
+ module Asposecellsjava
7
+
8
+ class << self
9
+ attr_accessor :aspose_cells_config
10
+ end
11
+
12
+ def initialize_aspose_cells
13
+ aspose_jars_dir = Asposecellsjava.aspose_cells_config ? Asposecellsjava.aspose_cells_config['jar_dir'] : nil
14
+ aspose_license_path = Asposecellsjava.aspose_cells_config ? Asposecellsjava.aspose_cells_config['license_path'] : nil
15
+ jvm_args = Asposecellsjava.aspose_cells_config ? Asposecellsjava.aspose_cells_config['jvm_args'] : nil
16
+
17
+ load_aspose_jars(aspose_jars_dir, jvm_args)
18
+ load_aspose_license(aspose_license_path)
19
+ end
20
+
21
+ def load_aspose_license(aspose_license_path)
22
+ if aspose_license_path && File.exist?(aspose_license_path)
23
+ set_license(File.join(aspose_license_path))
24
+ else
25
+ logger = Logger.new(STDOUT)
26
+ logger.level = Logger::WARN
27
+ logger.warn('Using the non licensed aspose jar. Please specify path to your aspose license directory in config/aspose.yml file!')
28
+ end
29
+ end
30
+
31
+ def load_aspose_jars(aspose_jars_dir, jvm_args)
32
+ if aspose_jars_dir && File.exist?(aspose_jars_dir)
33
+ jardir = File.join(aspose_jars_dir, '**', '*.jar')
34
+ else
35
+ jardir = File.join(File.dirname(File.dirname(__FILE__)), 'jars', '**', '*.jar')
36
+ end
37
+
38
+ if jvm_args
39
+ args = jvm_args.split(' ') << '-Djava.awt.headless=true'
40
+ logger = Logger.new(STDOUT)
41
+ logger.level = Logger::DEBUG
42
+ logger.debug("JVM args : #{args}")
43
+ Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=args)
44
+ else
45
+ Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true'])
46
+ end
47
+
48
+ end
49
+
50
+ def input_file(file)
51
+ Rjb::import('java.io.FileInputStream').new(file)
52
+ end
53
+
54
+ def set_license(aspose_license_file)
55
+ begin
56
+ fstream = input_file(aspose_license_file)
57
+ license = Rjb::import('com.aspose.api.License').new()
58
+ license.setLicense(fstream)
59
+ rescue Exception => ex
60
+ logger = Logger.new(STDOUT)
61
+ logger.level = Logger::ERROR
62
+ logger.error("Could not load the license file : #{ex}")
63
+ fstream.close() if fstream
64
+ end
65
+ end
66
+
67
+ def self.configure_aspose_cells config
68
+ Asposecellsjava.aspose_cells_config = config
69
+ end
70
+
71
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'hideunhideworksheet'
2
+ require_relative 'displayhidetabs'
3
+ require_relative 'displayhidescrollbars'
4
+ require_relative 'displayhidegridlines'
5
+ require_relative 'displayhiderowcolumnheaders'
6
+ require_relative 'pagebreakpreview'
7
+ require_relative 'zoomfactor'
8
+ require_relative 'freezepanes'
9
+ require_relative 'splitpanes'
10
+ require_relative 'managingworksheets'
11
+ require_relative 'pagebreaks'
12
+ require_relative 'copyworksheets'
13
+ require_relative 'converter'
14
+ require_relative 'encrypt'
15
+ require_relative 'document'
16
+ require_relative 'rowsandcolumns'
17
+ require_relative 'protection'
18
+ require_relative 'pagesetup'
@@ -0,0 +1,213 @@
1
+ module Asposecellsjava
2
+ module Converter
3
+ def initialize()
4
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
5
+
6
+ # Instantiating a Workbook object by excel file path
7
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(@data_dir + 'Book1.xls')
8
+
9
+ # Converting Excel to PDF
10
+ excel_to_pdf(workbook)
11
+
12
+ # Converting Chart to Image
13
+ chart_to_image()
14
+
15
+ # Converting Worksheet to Image
16
+ worksheet_to_image(workbook)
17
+
18
+ # Converting Worksheet to SVG
19
+ worksheet_to_svg(workbook)
20
+
21
+ # Converting Worksheet to MHTML
22
+ worksheet_to_mhtml(workbook)
23
+
24
+ # Converting Worksheet to HTML
25
+ worksheet_to_html(workbook)
26
+
27
+ # Converting HTML to Excel
28
+ html_to_excel()
29
+ end
30
+
31
+ def excel_to_pdf(workbook)
32
+ save_format = Rjb::import('com.aspose.cells.SaveFormat')
33
+
34
+ # Save the document in PDF format
35
+ workbook.save(@data_dir + "MyPdfFile.pdf", save_format.PDF)
36
+
37
+ puts "Pdf saved successfully."
38
+ end
39
+
40
+ def chart_to_image()
41
+ # Create a new Workbook.
42
+ workbook = Rjb::import('com.aspose.cells.Workbook').new
43
+
44
+ # Get the first worksheet.
45
+ sheet = workbook.getWorksheets().get(0)
46
+
47
+ # Set the name of worksheet
48
+ sheet.setName("Data")
49
+
50
+ # Get the cells collection in the sheet.
51
+ cells = workbook.getWorksheets().get(0).getCells()
52
+
53
+ # Put some values into a cells of the Data sheet.
54
+ cells.get("A1").setValue("Region")
55
+ cells.get("A2").setValue("France")
56
+ cells.get("A3").setValue("Germany")
57
+ cells.get("A4").setValue("England")
58
+ cells.get("A5").setValue("Sweden")
59
+ cells.get("A6").setValue("Italy")
60
+ cells.get("A7").setValue("Spain")
61
+ cells.get("A8").setValue("Portugal")
62
+ cells.get("B1").setValue("Sale")
63
+ cells.get("B2").setValue(70000)
64
+ cells.get("B3").setValue(55000)
65
+ cells.get("B4").setValue(30000)
66
+ cells.get("B5").setValue(40000)
67
+ cells.get("B6").setValue(35000)
68
+ cells.get("B7").setValue(32000)
69
+ cells.get("B8").setValue(10000)
70
+
71
+ # Create chart
72
+ chart_type = Rjb::import('com.aspose.cells.ChartType')
73
+ chart_index = sheet.getCharts().add(chart_type.COLUMN, 12, 1, 33, 12)
74
+ chart = sheet.getCharts().get(chart_index)
75
+
76
+ # Set properties of chart title
77
+ chart.getTitle().setText("Sales By Region")
78
+ chart.getTitle().getFont().setBold(true)
79
+ chart.getTitle().getFont().setSize(12)
80
+
81
+ # Set properties of nseries
82
+ chart.getNSeries().add("Data!B2:B8", true)
83
+ chart.getNSeries().setCategoryData("Data!A2:A8")
84
+
85
+ # Set the fill colors for the series's data points (France - Portugal(7 points))
86
+ chart_points = chart.getNSeries().get(0).getPoints()
87
+
88
+ color = Rjb::import('com.aspose.cells.Color')
89
+
90
+ point = chart_points.get(0)
91
+ point.getArea().setForegroundColor(color.getCyan())
92
+
93
+ point = chart_points.get(1)
94
+ point.getArea().setForegroundColor(color.getBlue())
95
+
96
+ point = chart_points.get(2)
97
+ point.getArea().setForegroundColor(color.getYellow())
98
+
99
+ point = chart_points.get(3)
100
+ point.getArea().setForegroundColor(color.getRed())
101
+
102
+ point = chart_points.get(4)
103
+ point.getArea().setForegroundColor(color.getBlack())
104
+
105
+ point = chart_points.get(5)
106
+ point.getArea().setForegroundColor(color.getGreen())
107
+
108
+ point = chart_points.get(6)
109
+ point.getArea().setForegroundColor(color.getMaroon())
110
+
111
+ # Set the legend invisible
112
+ chart.setShowLegend(false)
113
+
114
+ # Get the Chart image
115
+ img_opts = Rjb::import('com.aspose.cells.ImageOrPrintOptions').new
116
+ image_format = Rjb::import('com.aspose.cells.ImageFormat')
117
+ img_opts.setImageFormat(image_format.getPng())
118
+
119
+ # Save the chart image file.
120
+ chart.toImage(@data_dir + "MyChartImage.png", img_opts)
121
+
122
+ # Print message
123
+ puts "Convert chart to image successfully."
124
+ end
125
+
126
+ def worksheet_to_image(workbook)
127
+ #Create an object for ImageOptions
128
+ img_options = Rjb::import('com.aspose.cells.ImageOrPrintOptions').new
129
+
130
+ # Set the image type
131
+ image_format = Rjb::import('com.aspose.cells.ImageFormat')
132
+ img_options.setImageFormat(image_format.getPng())
133
+
134
+ # Get the first worksheet.
135
+ sheet = workbook.getWorksheets().get(0)
136
+
137
+ # Create a SheetRender object for the target sheet
138
+ sr = Rjb::import('com.aspose.cells.SheetRender').new(sheet, img_options)
139
+
140
+ j = 0
141
+ while j < sr.getPageCount()
142
+ # Generate an image for the worksheet
143
+ sr.toImage(j, @data_dir + "mysheetimg_#{j}.png")
144
+ j +=1
145
+ end
146
+
147
+ puts "Image saved successfully."
148
+ end
149
+
150
+ def worksheet_to_svg(workbook)
151
+ # Convert each worksheet into svg format in a single page.
152
+ img_options = Rjb::import('com.aspose.cells.ImageOrPrintOptions').new
153
+ save_format = Rjb::import('com.aspose.cells.SaveFormat')
154
+ img_options.setSaveFormat(save_format.SVG)
155
+ img_options.setOnePagePerSheet(true)
156
+
157
+ # Convert each worksheet into svg format
158
+ sheet_count = workbook.getWorksheets().getCount()
159
+
160
+ i=0
161
+ while i < sheet_count
162
+ sheet = workbook.getWorksheets().get(i)
163
+
164
+ sr = Rjb::import('com.aspose.cells.SheetRender').new(sheet, img_options)
165
+
166
+ k=0
167
+ while sr.getPageCount()
168
+ # Output the worksheet into Svg image format
169
+ sr.toImage(k, @data_dir + sheet.getName() + "#{k}.svg")
170
+ end
171
+ end
172
+
173
+ puts "SVG saved successfully."
174
+ end
175
+
176
+ def worksheet_to_mhtml(workbook)
177
+ save_format = Rjb::import('com.aspose.cells.SaveFormat')
178
+ # Specify the HTML saving options
179
+ sv = Rjb::import('com.aspose.cells.HtmlSaveOptions').new(save_format.M_HTML)
180
+
181
+ # Save the document
182
+ workbook.save(@data_dir + "convert.mht", sv)
183
+
184
+ puts "MHTML saved successfully."
185
+ end
186
+
187
+ def worksheet_to_html(workbook)
188
+ save_format = Rjb::import('com.aspose.cells.SaveFormat')
189
+ # Specify the HTML saving options
190
+ save = Rjb::import('com.aspose.cells.HtmlSaveOptions').new(save_format.M_HTML)
191
+
192
+ # Save the document
193
+ workbook.save(@data_dir + "output.html", save)
194
+
195
+ puts "HTML saved successfully."
196
+ end
197
+
198
+ def html_to_excel()
199
+ load_format = Rjb::import('com.aspose.cells.LoadFormat')
200
+ # Create an instance of HTMLLoadOptions and initiate it with appropriate LoadFormat
201
+ options = Rjb::import('com.aspose.cells.HTMLLoadOptions').new(load_format.HTML)
202
+
203
+ # Load the Html file through file path while passing the instance of HTMLLoadOptions class
204
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(@data_dir + "index.html", options)
205
+
206
+ save_format = Rjb::import('com.aspose.cells.SaveFormat')
207
+ #Save the results to disc in Xlsx format
208
+ workbook.save(@data_dir + "output.xlsx", save_format.XLSX)
209
+
210
+ puts "XLSX saved successfully."
211
+ end
212
+ end
213
+ end