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.
@@ -0,0 +1,54 @@
1
+ module Asposecellsjava
2
+ module PageSetup
3
+ def initialize()
4
+ # Page Orientation
5
+ page_orientation()
6
+
7
+ # Scaling Factor
8
+ scaling()
9
+ end
10
+
11
+ def page_orientation()
12
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
13
+
14
+ # Instantiating a Workbook object by excel file path
15
+ workbook = Rjb::import('com.aspose.cells.Workbook').new
16
+
17
+ # Accessing the first worksheet in the Excel file
18
+ worksheets = workbook.getWorksheets()
19
+ sheet_index = worksheets.add()
20
+ sheet = worksheets.get(sheet_index)
21
+
22
+ # Setting the orientation to Portrait
23
+ page_setup = sheet.getPageSetup()
24
+ page_orientation_type = Rjb::import('com.aspose.cells.PageOrientationType')
25
+ page_setup.setOrientation(page_orientation_type.PORTRAIT)
26
+
27
+ # Saving the modified Excel file in default (that is Excel 2003) format
28
+ workbook.save(data_dir + "Page Orientation.xls")
29
+
30
+ puts "Set page orientation, please check the output file."
31
+ end
32
+
33
+ def scaling()
34
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
35
+
36
+ # Instantiating a Workbook object by excel file path
37
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
38
+
39
+ # Accessing the first worksheet in the Excel file
40
+ worksheets = workbook.getWorksheets()
41
+ sheet_index = worksheets.add()
42
+ sheet = worksheets.get(sheet_index)
43
+
44
+ # Setting the scaling factor to 100
45
+ page_setup = sheet.getPageSetup()
46
+ page_setup.setZoom(100)
47
+
48
+ # Saving the modified Excel file in default (that is Excel 2003) format
49
+ workbook.save(data_dir + "Scaling.xls")
50
+
51
+ puts "Set scaling, please check the output file."
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,63 @@
1
+ module Asposecellsjava
2
+ module Protection
3
+ def initialize()
4
+ # Proctect a Worksheet
5
+ protect_worksheet()
6
+
7
+ # Unproctect a Worksheet
8
+ unprotect_worksheet()
9
+ end
10
+
11
+ def protect_worksheet()
12
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
13
+
14
+ # Instantiating a Workbook object by excel file path
15
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
16
+
17
+ # Accessing the first worksheet in the Excel file
18
+ worksheets = workbook.getWorksheets()
19
+ worksheet = worksheets.get(0)
20
+
21
+ protection = worksheet.getProtection()
22
+
23
+ # The following 3 methods are only for Excel 2000 and earlier formats
24
+ protection.setAllowEditingContent(false)
25
+ protection.setAllowEditingObject(false)
26
+ protection.setAllowEditingScenario(false)
27
+
28
+ # Protects the first worksheet with a password "1234"
29
+ protection.setPassword("1234")
30
+
31
+ # Saving the modified Excel file in default (that is Excel 2003) format
32
+ workbook.save(data_dir + "Protect Worksheet.xls")
33
+
34
+ puts "Protect a Worksheet, please check the output file."
35
+ end
36
+
37
+ def unprotect_worksheet()
38
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
39
+
40
+ # Instantiating a Workbook object by excel file path
41
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
42
+
43
+ # Accessing the first worksheet in the Excel file
44
+ worksheets = workbook.getWorksheets()
45
+ worksheet = worksheets.get(0)
46
+
47
+ protection = worksheet.getProtection()
48
+
49
+ # The following 3 methods are only for Excel 2000 and earlier formats
50
+ protection.setAllowEditingContent(false)
51
+ protection.setAllowEditingObject(false)
52
+ protection.setAllowEditingScenario(false)
53
+
54
+ # Unprotecting the worksheet with a password
55
+ worksheet.unprotect("1234")
56
+
57
+ # Saving the modified Excel file in default (that is Excel 2003) format
58
+ workbook.save(data_dir + "Unprotect Worksheet.xls")
59
+
60
+ puts "Unprotect a Worksheet, please check the output file."
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,392 @@
1
+ module Asposecellsjava
2
+ module RowsAndColumns
3
+ def initialize()
4
+ # Inserting a Row
5
+ insert_row()
6
+
7
+ # Inserting Multiple Rows
8
+ insert_multiple_rows()
9
+
10
+ # Deleting a Row
11
+ delete_row()
12
+
13
+ # Deleting Multiple Rows
14
+ delete_multiple_rows()
15
+
16
+ # Inseting one or Multiple Columns
17
+ insert_column()
18
+
19
+ # Deleting a Column
20
+ delete_column()
21
+
22
+ # Hiding Rows and Columns
23
+ hide_rows_columns()
24
+
25
+ # Showing Rows and Columns
26
+ unhide_rows_columns()
27
+
28
+ # Grouping Rows & Columns
29
+ group_rows_columns()
30
+
31
+ # Ungrouping Rows & Columns
32
+ ungroup_rows_columns()
33
+
34
+ # Setting the Row Height
35
+ set_row_height()
36
+
37
+ # Setting the Width of a Column
38
+ set_column_width()
39
+
40
+ # Auto Fit Row
41
+ autofit_row()
42
+
43
+ # Auto Fit Column
44
+ autofit_column()
45
+
46
+ # Copying Rows
47
+ copy_rows()
48
+
49
+ # Copying Columns
50
+ copy_columns()
51
+ end
52
+
53
+ def insert_row()
54
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
55
+
56
+ # Instantiating a Workbook object by excel file path
57
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
58
+
59
+ # Accessing the first worksheet in the Excel file
60
+ worksheet = workbook.getWorksheets().get(0)
61
+
62
+ # Inserting a row into the worksheet at 3rd position
63
+ worksheet.getCells().insertRows(2,1)
64
+
65
+ # Saving the modified Excel file in default (that is Excel 2003) format
66
+ workbook.save(data_dir + "Insert Row.xls")
67
+
68
+ puts "Insert Row Successfully."
69
+ end
70
+
71
+ def insert_multiple_rows()
72
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
73
+
74
+ # Instantiating a Workbook object by excel file path
75
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
76
+
77
+ # Accessing the first worksheet in the Excel file
78
+ worksheet = workbook.getWorksheets().get(0)
79
+
80
+ # Inserting a row into the worksheet at 3rd position
81
+ worksheet.getCells().insertRows(2,10)
82
+
83
+ # Saving the modified Excel file in default (that is Excel 2003) format
84
+ workbook.save(data_dir + "Insert Multiple Rows.xls")
85
+
86
+ puts "Insert Multiple Rows Successfully."
87
+ end
88
+
89
+ def delete_row()
90
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
91
+
92
+ # Instantiating a Workbook object by excel file path
93
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
94
+
95
+ # Accessing the first worksheet in the Excel file
96
+ worksheet = workbook.getWorksheets().get(0)
97
+
98
+ # Deleting 3rd row from the worksheet
99
+ worksheet.getCells().deleteRows(2,1,true)
100
+
101
+ # Saving the modified Excel file in default (that is Excel 2003) format
102
+ workbook.save(data_dir + "Delete Row.xls")
103
+
104
+ puts "Delete Row Successfully."
105
+ end
106
+
107
+ def delete_multiple_rows()
108
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
109
+
110
+ # Instantiating a Workbook object by excel file path
111
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
112
+
113
+ # Accessing the first worksheet in the Excel file
114
+ worksheet = workbook.getWorksheets().get(0)
115
+
116
+ # Deleting 10 rows from the worksheet starting from 3rd row
117
+ worksheet.getCells().deleteRows(2,10,true)
118
+
119
+ # Saving the modified Excel file in default (that is Excel 2003) format
120
+ workbook.save(data_dir + "Delete Multiple Rows.xls")
121
+
122
+ puts "Delete Multiple Rows Successfully."
123
+ end
124
+
125
+ def insert_column()
126
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
127
+
128
+ # Instantiating a Workbook object by excel file path
129
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
130
+
131
+ # Accessing the first worksheet in the Excel file
132
+ worksheet = workbook.getWorksheets().get(0)
133
+
134
+ # Inserting a column into the worksheet at 2nd position
135
+ worksheet.getCells().insertColumns(1,1)
136
+
137
+ # Saving the modified Excel file in default (that is Excel 2003) format
138
+ workbook.save(data_dir + "Insert Column.xls")
139
+
140
+ puts "Insert Column Successfully."
141
+ end
142
+
143
+ def delete_column()
144
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
145
+
146
+ # Instantiating a Workbook object by excel file path
147
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
148
+
149
+ # Accessing the first worksheet in the Excel file
150
+ worksheet = workbook.getWorksheets().get(0)
151
+
152
+ # Deleting a column from the worksheet at 2nd position
153
+ worksheet.getCells().deleteColumns(1,1,true)
154
+
155
+ # Saving the modified Excel file in default (that is Excel 2003) format
156
+ workbook.save(data_dir + "Delete Column.xls")
157
+
158
+ puts "Delete Column Successfully."
159
+ end
160
+
161
+ def hide_rows_columns()
162
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
163
+
164
+ # Instantiating a Workbook object by excel file path
165
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
166
+
167
+ # Accessing the first worksheet in the Excel file
168
+ worksheet = workbook.getWorksheets().get(0)
169
+ cells = worksheet.getCells()
170
+
171
+ # Hiding the 3rd row of the worksheet
172
+ cells.hideRow(2)
173
+
174
+ # Hiding the 2nd column of the worksheet
175
+ cells.hideColumn(1)
176
+
177
+ # Saving the modified Excel file in default (that is Excel 2003) format
178
+ workbook.save(data_dir + "Hide Rows And Columns.xls")
179
+
180
+ puts "Hide Rows And Columns Successfully."
181
+ end
182
+
183
+ def unhide_rows_columns()
184
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
185
+
186
+ # Instantiating a Workbook object by excel file path
187
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
188
+
189
+ # Accessing the first worksheet in the Excel file
190
+ worksheet = workbook.getWorksheets().get(0)
191
+ cells = worksheet.getCells()
192
+
193
+ # Unhiding the 3rd row and setting its height to 13.5
194
+ cells.unhideRow(2,13.5)
195
+
196
+ # Unhiding the 2nd column and setting its width to 8.5
197
+ cells.unhideColumn(1,8.5)
198
+
199
+ # Saving the modified Excel file in default (that is Excel 2003) format
200
+ workbook.save(data_dir + "Unhide Rows And Columns.xls")
201
+
202
+ puts "Unhide Rows And Columns Successfully."
203
+ end
204
+
205
+ def group_rows_columns()
206
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
207
+
208
+ # Instantiating a Workbook object by excel file path
209
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
210
+
211
+ # Accessing the first worksheet in the Excel file
212
+ worksheet = workbook.getWorksheets().get(0)
213
+ cells = worksheet.getCells()
214
+
215
+ # Grouping first six rows (from 0 to 5) and making them hidden by passing true
216
+ cells.groupRows(0,5,true)
217
+
218
+ # Grouping first three columns (from 0 to 2) and making them hidden by passing true
219
+ cells.groupColumns(0,2,true)
220
+
221
+ # Saving the modified Excel file in default (that is Excel 2003) format
222
+ workbook.save(data_dir + "Group Rows And Columns.xls")
223
+
224
+ puts "Group Rows And Columns Successfully."
225
+ end
226
+
227
+ def ungroup_rows_columns()
228
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
229
+
230
+ # Instantiating a Workbook object by excel file path
231
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Group Rows And Columns.xls')
232
+
233
+ # Accessing the first worksheet in the Excel file
234
+ worksheet = workbook.getWorksheets().get(0)
235
+ cells = worksheet.getCells()
236
+
237
+ # Ungrouping first six rows (from 0 to 5)
238
+ cells.ungroupRows(0,5)
239
+
240
+ # Ungrouping first three columns (from 0 to 2)
241
+ cells.ungroupColumns(0,2)
242
+
243
+ # Saving the modified Excel file in default (that is Excel 2003) format
244
+ workbook.save(data_dir + "Ungroup Rows And Columns.xls")
245
+
246
+ puts "Ungroup Rows And Columns Successfully."
247
+ end
248
+
249
+ def set_row_height()
250
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
251
+
252
+ # Instantiating a Workbook object by excel file path
253
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
254
+
255
+ # Accessing the first worksheet in the Excel file
256
+ worksheet = workbook.getWorksheets().get(0)
257
+ cells = worksheet.getCells()
258
+
259
+ # Setting the height of the second row to 13
260
+ cells.setRowHeight(1, 13)
261
+
262
+ # Saving the modified Excel file in default (that is Excel 2003) format
263
+ workbook.save(data_dir + "Set Row Height.xls")
264
+
265
+ puts "Set Row Height Successfully."
266
+ end
267
+
268
+ def set_column_width()
269
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
270
+
271
+ # Instantiating a Workbook object by excel file path
272
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
273
+
274
+ # Accessing the first worksheet in the Excel file
275
+ worksheet = workbook.getWorksheets().get(0)
276
+ cells = worksheet.getCells()
277
+
278
+ # Setting the width of the second column to 17.5
279
+ cells.setColumnWidth(1, 17.5)
280
+
281
+ # Saving the modified Excel file in default (that is Excel 2003) format
282
+ workbook.save(data_dir + "Set Column Width.xls")
283
+
284
+ puts "Set Column Width Successfully."
285
+ end
286
+
287
+ def autofit_row()
288
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
289
+
290
+ # Instantiating a Workbook object by excel file path
291
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
292
+
293
+ # Accessing the first worksheet in the Excel file
294
+ worksheet = workbook.getWorksheets().get(0)
295
+
296
+ # Auto-fitting the 3rd row of the worksheet
297
+ worksheet.autoFitRow(2)
298
+
299
+ # Auto-fitting the 3rd row of the worksheet based on the contents in a range of
300
+ # cells (from 1st to 9th column) within the row
301
+ #worksheet.autoFitRow(2,0,8) # Uncomment this line if you to do AutoFit Row in a Range of Cells. Also, comment line 288.
302
+
303
+ # Saving the modified Excel file in default (that is Excel 2003) format
304
+ workbook.save(data_dir + "Autofit Row.xls")
305
+
306
+ puts "Autofit Row Successfully."
307
+ end
308
+
309
+ def autofit_column()
310
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
311
+
312
+ # Instantiating a Workbook object by excel file path
313
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
314
+
315
+ # Accessing the first worksheet in the Excel file
316
+ worksheet = workbook.getWorksheets().get(0)
317
+
318
+ # Auto-fitting the 4th column of the worksheet
319
+ worksheet.autoFitColumn(3)
320
+
321
+ # Auto-fitting the 4th column of the worksheet based on the contents in a range of
322
+ # cells (from 1st to 9th row) within the column
323
+ #worksheet.autoFitColumn(3,0,8) #Uncomment this line if you to do AutoFit Column in a Range of Cells. Also, comment line 310.
324
+
325
+ # Saving the modified Excel file in default (that is Excel 2003) format
326
+ workbook.save(data_dir + "Autofit Column.xls")
327
+
328
+ puts "Autofit Column Successfully."
329
+ end
330
+
331
+ def copy_rows()
332
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
333
+
334
+ # Instantiating a Workbook object by excel file path
335
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
336
+
337
+ # Accessing the first worksheet in the Excel file
338
+ worksheet = workbook.getWorksheets().get(0)
339
+
340
+ # Copy the second row with data, formattings, images and drawing objects
341
+ # to the 12th row in the worksheet.
342
+ worksheet.getCells().copyRow(worksheet.getCells(),1,11);
343
+
344
+ # Saving the modified Excel file in default (that is Excel 2003) format
345
+ workbook.save(data_dir + "Copy Rows.xls")
346
+
347
+ puts "Copy Rows Successfully."
348
+ end
349
+
350
+ def copy_columns()
351
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
352
+
353
+ # Instantiating a Workbook object by excel file path
354
+ workbook = Rjb::import('com.aspose.cells.Workbook').new
355
+
356
+ # Accessing the first worksheet in the Excel file
357
+ worksheet = workbook.getWorksheets().get(0)
358
+
359
+ # Put some data into header rows (A1:A4)
360
+ i = 0
361
+ while i < 5
362
+ worksheet.getCells().get(i, 0).setValue("Header Row #{i}")
363
+ i +=1
364
+ end
365
+
366
+ # Put some detail data (A5:A999)
367
+ i = 5
368
+ while i < 1000
369
+ worksheet.getCells().get(i, 0).setValue("Detail Row #{i}")
370
+ i +=1
371
+ end
372
+
373
+ # Create another Workbook.
374
+ workbook1 = Rjb::import('com.aspose.cells.Workbook').new
375
+
376
+ # Get the first worksheet in the book.
377
+ worksheet1 = workbook1.getWorksheets().get(0)
378
+
379
+ # Copy the first column from the first worksheet of the first workbook into
380
+ # the first worksheet of the second workbook.
381
+ worksheet1.getCells().copyColumn(worksheet.getCells(),0,2)
382
+
383
+ # Autofit the column.
384
+ worksheet1.autoFitColumn(2)
385
+
386
+ # Saving the modified Excel file in default (that is Excel 2003) format
387
+ workbook.save(data_dir + "Copy Columns.xls")
388
+
389
+ puts "Copy Columns Successfully."
390
+ end
391
+ end
392
+ end