asposecellsjava 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ module Asposecellsjava
2
+ module CopyWorksheets
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
+ # Copy Worksheets within a Workbook
10
+ copy_worksheet(workbook)
11
+
12
+ # Move Worksheets within Workbook
13
+ move_worksheet(workbook)
14
+ end
15
+
16
+ def copy_worksheet(workbook)
17
+ # Create a Worksheets object with reference to the sheets of the Workbook.
18
+ sheets = workbook.getWorksheets()
19
+
20
+ # Copy data to a new sheet from an existing sheet within the Workbook.
21
+ sheets.addCopy("Sheet1")
22
+
23
+ # Saving the modified Excel file in default (that is Excel 2003) format
24
+ workbook.save(@data_dir + "Copy Worksheet.xls")
25
+
26
+ puts "Copy worksheet, please check the output file."
27
+ end
28
+
29
+ def move_worksheet(workbook)
30
+ # Get the first worksheet in the book.
31
+ sheet = workbook.getWorksheets().get(0)
32
+
33
+ # Move the first sheet to the third position in the workbook.
34
+ sheet.moveTo(2)
35
+
36
+ # Saving the modified Excel file in default (that is Excel 2003) format
37
+ workbook.save(@data_dir + "Move Worksheet.xls")
38
+
39
+ puts "Move worksheet, please check the output file."
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ module Asposecellsjava
2
+ module DisplayHideGridlines
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
+ # Accessing the first worksheet in the Excel file
10
+ worksheets = workbook.getWorksheets()
11
+ sheet_index = worksheets.add()
12
+ worksheet = worksheets.get(sheet_index)
13
+
14
+ # Hiding the gridlines of the first worksheet of the Excel file
15
+ worksheet.setGridlinesVisible(false)
16
+
17
+ # Saving the modified Excel file in default (that is Excel 2003) format
18
+ workbook.save(data_dir + "output.xls")
19
+
20
+ puts "Gridlines are now hidden, please check the output file."
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Asposecellsjava
2
+ module DisplayHideRowColumnHeaders
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
+ # Accessing the first worksheet in the Excel file
10
+ worksheets = workbook.getWorksheets()
11
+ sheet_index = worksheets.add()
12
+ worksheet = worksheets.get(sheet_index)
13
+
14
+ # Hiding the headers of rows and columns
15
+ worksheet.setRowColumnHeadersVisible(false)
16
+
17
+ # Saving the modified Excel file in default (that is Excel 2003) format
18
+ workbook.save(data_dir + "output.xls")
19
+
20
+ puts "Headers of rows and columns are now hidden, please check the output file."
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ module Asposecellsjava
2
+ module DisplayHideScrollBars
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
+ # Hiding the vertical scroll bar of the Excel file
10
+ workbook.getSettings().setVScrollBarVisible(false)
11
+
12
+ # Hiding the horizontal scroll bar of the Excel file
13
+ workbook.getSettings().setHScrollBarVisible(false)
14
+
15
+ # Saving the modified Excel file in default (that is Excel 2003) format
16
+ workbook.save(data_dir + "output.xls")
17
+
18
+ puts "Scroll Bars are now hidden, please check the output file."
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module Asposecellsjava
2
+ module DisplayHideTabs
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
+ # Hiding the tabs of the Excel file
10
+ workbook.getSettings().setShowTabs(false)
11
+
12
+ # Saving the modified Excel file in default (that is Excel 2003) format
13
+ workbook.save(data_dir + "output.xls")
14
+
15
+ puts "Tabs are now hidden, please check the output file."
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,67 @@
1
+ module Asposecellsjava
2
+ module Document
3
+ def initialize()
4
+ # Accessing Document Properties
5
+ get_properties()
6
+
7
+ # Adding Custom Property
8
+ add_custom_property()
9
+
10
+ # Removing Custom Properties
11
+ remove_custom_property()
12
+ end
13
+
14
+ def get_properties()
15
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
16
+
17
+ # Instantiating a Workbook object by excel file path
18
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
19
+
20
+ # Retrieve a list of all custom document properties of the Excel file
21
+ custom_properties = workbook.getWorksheets().getCustomDocumentProperties()
22
+
23
+ # Accessng a custom document property by using the property index
24
+ puts "Property By Index: " + custom_properties.get(1).to_string
25
+
26
+ # Accessng a custom document property by using the property name
27
+ puts "Property By Name: " + custom_properties.get("Publisher").to_string
28
+ end
29
+
30
+ def add_custom_property()
31
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
32
+
33
+ # Instantiating a Workbook object by excel file path
34
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
35
+
36
+ # Retrieve a list of all custom document properties of the Excel file
37
+ #custom_properties = Rjb::import('java.util.ArrayList').new
38
+ custom_properties = workbook.getWorksheets().getCustomDocumentProperties()
39
+
40
+ # Adding a custom document property to the Excel file
41
+ custom_properties.add("Publisher", "Aspose")
42
+
43
+ # Save the document in PDF format
44
+ workbook.save(data_dir + "Add_Property.xls")
45
+
46
+ puts "Added custom property successfully."
47
+ end
48
+
49
+ def remove_custom_property()
50
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
51
+
52
+ # Instantiating a Workbook object by excel file path
53
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(data_dir + 'Book1.xls')
54
+
55
+ # Retrieve a list of all custom document properties of the Excel file
56
+ custom_properties = workbook.getWorksheets().getCustomDocumentProperties()
57
+
58
+ # Adding a custom document property to the Excel file
59
+ custom_properties.remove("Publisher")
60
+
61
+ # Save the document in PDF format
62
+ workbook.save(data_dir + "Removed_Property.xls")
63
+
64
+ puts "Removed custom property successfully."
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,26 @@
1
+ module Asposecellsjava
2
+ module Encrypt
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
+ # Password protect the file.
10
+ workbook.getSettings().setPassword("1234")
11
+
12
+ encryption_type = Rjb::import('com.aspose.cells.EncryptionType')
13
+
14
+ # Specify XOR encrption type.
15
+ workbook.setEncryptionOptions(encryption_type.XOR, 40)
16
+
17
+ # Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
18
+ workbook.setEncryptionOptions(encryption_type.STRONG_CRYPTOGRAPHIC_PROVIDER, 128)
19
+
20
+ # Saving the modified Excel file in default (that is Excel 2003) format
21
+ workbook.save(data_dir + "encrypt.xls")
22
+
23
+ puts "Apply encryption, please check the output file."
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Asposecellsjava
2
+ module FreezePanes
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
+ # Accessing the first worksheet in the Excel file
10
+ worksheets = workbook.getWorksheets()
11
+ worksheet = worksheets.get(0)
12
+
13
+ # Applying freeze panes settings
14
+ worksheet.freezePanes(3,2,3,2)
15
+
16
+ # Saving the modified Excel file in default (that is Excel 2003) format
17
+ workbook.save(data_dir + "output.xls")
18
+
19
+ puts "Apply freeze panes settings, please check the output file."
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Asposecellsjava
2
+ module HideUnhideWorksheet
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
+ # Accessing the first worksheet in the Excel file
10
+ #worksheets = Rjb::import('java.util.ArrayList').new
11
+ worksheets = workbook.getWorksheets()
12
+ worksheet = worksheets.get(0)
13
+
14
+ # Hiding the first worksheet of the Excel file
15
+ worksheet.setVisible(false)
16
+
17
+ # Saving the modified Excel file in default (that is Excel 2003) format
18
+ workbook.save(data_dir + "output.xls")
19
+
20
+ puts "Worksheet 1 is now hidden, please check the output document."
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,107 @@
1
+ module Asposecellsjava
2
+ module ManagingWorksheets
3
+ def initialize()
4
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
5
+
6
+ # Adding Worksheets to a New Excel File
7
+ add_worksheet(workbook)
8
+
9
+ # Adding Worksheets to a Designer Spreadsheet
10
+ add_worksheet_to_designer_spreadsheet()
11
+
12
+ # Accessing Worksheets using Sheet Name
13
+ get_worksheet()
14
+
15
+ # Removing Worksheets using Sheet Name
16
+ remove_worksheet_by_name()
17
+
18
+ # Removing Worksheets using Sheet Name
19
+ remove_worksheet_by_index()
20
+ end
21
+
22
+ def add_worksheet()
23
+ # Instantiating a Workbook object
24
+ workbook = Rjb::import('com.aspose.cells.Workbook').new
25
+
26
+ # Adding a new worksheet to the Workbook object
27
+ worksheets = workbook.getWorksheets()
28
+
29
+ sheet_index = worksheets.add()
30
+ worksheet = worksheets.get(sheet_index)
31
+
32
+ # Setting the name of the newly added worksheet
33
+ worksheet.setName("My Worksheet")
34
+
35
+ # Saving the modified Excel file in default (that is Excel 2003) format
36
+ workbook.save(@data_dir + "book.out.xls")
37
+
38
+ puts "Sheet added successfully."
39
+ end
40
+
41
+ def add_worksheet_to_designer_spreadsheet()
42
+ # Creating a file stream containing the Excel file to be opened
43
+ fstream = IO.sysopen(@data_dir + 'book1.xls', "w")
44
+
45
+ # Instantiating a Workbook object with the stream
46
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream)
47
+
48
+ # Adding a new worksheet to the Workbook object
49
+ worksheets = workbook.getWorksheets()
50
+ sheet_index = worksheets.add()
51
+ worksheet = worksheets.get(sheet_index)
52
+
53
+ # Setting the name of the newly added worksheet
54
+ worksheet.setName("My Worksheet")
55
+
56
+ # Saving the modified Excel file in default (that is Excel 2003) format
57
+ workbook.save(@data_dir + "book1.out.xls")
58
+ end
59
+
60
+ def get_worksheet()
61
+ # Creating a file stream containing the Excel file to be opened
62
+ fstream = IO.sysopen(@data_dir + 'book1.xls', "w")
63
+
64
+ # Instantiating a Workbook object with the stream
65
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream)
66
+
67
+ # Accessing a worksheet using its sheet name
68
+ worksheet = workbook.getWorksheets().get("Sheet1")
69
+
70
+ puts worksheet.to_string
71
+ end
72
+
73
+ def remove_worksheet_by_name()
74
+ # Creating a file stream containing the Excel file to be opened
75
+ fstream = IO.sysopen(@data_dir + 'book1.xls', "w")
76
+
77
+ # Instantiating a Workbook object with the stream
78
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream)
79
+
80
+ # Removing a worksheet using its sheet name
81
+ workbook.getWorksheets().removeAt("Sheet1")
82
+
83
+ # Saving the Excel file
84
+ workbook.save(@data_dir + "book.out.xls")
85
+
86
+ # Print Message
87
+ puts "Sheet removed successfully."
88
+ end
89
+
90
+ def remove_worksheet_by_index()
91
+ # Creating a file stream containing the Excel file to be opened
92
+ fstream = IO.sysopen(@data_dir + 'book1.xls', "w")
93
+
94
+ # Instantiating a Workbook object with the stream
95
+ workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream)
96
+
97
+ # Removing a worksheet using its sheet name
98
+ workbook.getWorksheets().removeAt(0)
99
+
100
+ # Saving the Excel file
101
+ workbook.save(@data_dir + "book.out.xls")
102
+
103
+ # Print Message
104
+ puts "Sheet removed successfully."
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,23 @@
1
+ module Asposecellsjava
2
+ module PageBreakPreview
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
+ # Accessing the first worksheet in the Excel file
10
+ worksheets = workbook.getWorksheets()
11
+ sheet_index = worksheets.add()
12
+ worksheet = worksheets.get(sheet_index)
13
+
14
+ # Displaying the worksheet in page break preview
15
+ worksheet.setPageBreakPreview(true)
16
+
17
+ # Saving the modified Excel file in default (that is Excel 2003) format
18
+ workbook.save(data_dir + "output.xls")
19
+
20
+ puts "Set page break preview, please check the output file."
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ module Asposecellsjava
2
+ module PageBreaks
3
+ def initialize()
4
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
5
+
6
+ # Instantiating a Workbook object
7
+ workbook = Rjb::import('com.aspose.cells.Workbook').new
8
+
9
+ # Adding Page Breaks
10
+ add_page_breaks(workbook)
11
+
12
+ # Clearing All Page Breaks
13
+ clear_all_page_breaks(workbook)
14
+
15
+ # Removing Specific Page Break
16
+ remove_page_break(workbook)
17
+ end
18
+
19
+ def add_page_breaks(workbook)
20
+ worksheets = workbook.getWorksheets()
21
+ worksheet = worksheets.get(0)
22
+
23
+ h_page_breaks = worksheet.getHorizontalPageBreaks()
24
+ h_page_breaks.add("Y30")
25
+
26
+ v_page_breaks = worksheet.getVerticalPageBreaks()
27
+ v_page_breaks.add("Y30")
28
+
29
+ # Saving the modified Excel file in default (that is Excel 2003) format
30
+ workbook.save(@data_dir + "Add Page Breaks.xls")
31
+
32
+ puts "Add page breaks, please check the output file."
33
+ end
34
+
35
+ def clear_all_page_breaks(workbook)
36
+ workbook.getWorksheets().get(0).getHorizontalPageBreaks().clear()
37
+ workbook.getWorksheets().get(0).getVerticalPageBreaks().clear()
38
+
39
+ # Saving the modified Excel file in default (that is Excel 2003) format
40
+ workbook.save(@data_dir + "Clear All Page Breaks.xls")
41
+
42
+ puts "Clear all page breaks, please check the output file."
43
+ end
44
+
45
+ def remove_page_break(workbook)
46
+ worksheets = workbook.getWorksheets()
47
+ worksheet = worksheets.get(0)
48
+
49
+ h_page_breaks = worksheet.getHorizontalPageBreaks()
50
+ h_page_breaks.removeAt(0)
51
+
52
+ v_page_breaks = worksheet.getVerticalPageBreaks()
53
+ v_page_breaks.removeAt(0)
54
+
55
+ # Saving the modified Excel file in default (that is Excel 2003) format
56
+ workbook.save(@data_dir + "Remove Page Break.xls")
57
+
58
+ puts "Remove page break, please check the output file."
59
+ end
60
+ end
61
+ end