thunderboltlabs-rubyXL 1.2.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmJiNjNlNjMyNTlmNzFlZmFjMzQ2Y2U4Y2IzZDQ2ZDA5NTdhOWY5Mg==
5
+ data.tar.gz: !binary |-
6
+ YzM0Y2ZhZTM5MjNlYzM0M2QyOTYwNWJkM2M4MjZmMWVhNzhkNWFiOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NmMwNjYxMDU0MDQ0Y2I1YTViZGFiNjliZmU1MWMwODkxZTU0MTM4MmVhY2Nl
10
+ OTM2NmIyNWY4YjQxODk3Y2Y5NTc4YzE2OWY4ZjQ4ZWM4M2Q3MWZmNThkYjY4
11
+ NmVjYzVhNDQwNDY1MDNjZDI3ZTA2M2M5Nzg3MTM5YTg4ODBhOTU=
12
+ data.tar.gz: !binary |-
13
+ NzYwM2M0MGQ3ZjJmNzgyMDEyODNjZjRmYmFjYThkYTI3ZWQ0MDMzY2M0ZjAw
14
+ YTM2NGJiZjA0MWIyNDJiYjcxOGNhZjIwZTc3NTU0YjJiMmU4Yzk5ZDYzNWZi
15
+ NmMxNGExNDRmZWNjOWIxMmY2ZGFkMTM3NmE3MWIxMTllMzQ0Yzk=
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.0"
12
+ gem "rcov", ">= 0"
13
+ gem "nokogiri", ">= 1.4.4"
14
+ gem "rubyzip", ">= 0.9.4"
15
+ gem "rspec", ">= 1.3.4"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ nokogiri (1.4.4)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.6.0)
14
+ rspec-core (~> 2.6.0)
15
+ rspec-expectations (~> 2.6.0)
16
+ rspec-mocks (~> 2.6.0)
17
+ rspec-core (2.6.4)
18
+ rspec-expectations (2.6.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.6.0)
21
+ rubyzip (0.9.4)
22
+ shoulda (2.11.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ jeweler (~> 1.6.0)
30
+ nokogiri (>= 1.4.4)
31
+ rcov
32
+ rspec (>= 1.3.4)
33
+ rubyzip (>= 0.9.4)
34
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Vivek Bhagwat
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,197 @@
1
+ = rubyXL
2
+
3
+ == To Install:
4
+ gem install rubyXL
5
+
6
+ == To Use:
7
+ require 'rubyXL' #assuming rubygems is already required
8
+
9
+ === Parsing an existing workbook
10
+ workbook = RubyXL::Parser.parse("path/to/Excel/file.xlsx")
11
+
12
+
13
+ === Creating a new Workbook
14
+ workbook = RubyXL::Workbook.new
15
+
16
+ === Accessing
17
+
18
+ ==== Accessing a Worksheet
19
+ workbook.worksheets[0] #returns first worksheet
20
+ workbook[0] #returns first worksheet
21
+
22
+ ==== Accessing Only the Values
23
+ workbook.worksheets[0].extract_data #produces a 2d array which consists only of the values (instead of the Cell objects which include other variables)
24
+
25
+ ==== Accessing a Row (Array of Cells)
26
+ workbook[0].sheet_data[0] #returns first row in first worksheet
27
+ workbook[0][0] #returns first row in first worksheet
28
+
29
+ ==== Accessing a Cell
30
+ workbook[0].sheet_data[0][0] #returns A1 in first worksheet
31
+ workbook[0][0][0] #returns A1 in first worksheet
32
+
33
+ ==== Accessing Cell properties
34
+ workbook[0][0][0].is_struckthrough() #returns if A1 is struckthrough, other boolean properties have same syntax
35
+ workbook[0][0][0].font_name #returns font name for A1
36
+ workbook[0][0][0].font_size #returns font size for A1
37
+ workbook[0][0][0].font_color #returns font color for A1
38
+ workbook[0][0][0].fill_color #returns fill color for A1
39
+ workbook[0][0][0].horizontal_alignment #returns horizontal alignment for A1 (or nil if it does not exist)
40
+ workbook[0][0][0].vertical_alignment #returns vertical alignment for A1 (or nil if it does not exist)
41
+ workbook[0][0][0].border_top #returns type of border on top of A1 (nil if none exists), other directions have same syntax
42
+
43
+ ==== Accessing row properties
44
+ workbook[0].get_row_fill(0) #returns fill color for first row
45
+ workbook[0].get_row_font_name(0) #returns font name for first row
46
+ workbook[0].get_row_font_size(0) #returns font size for first row
47
+ workbook[0].get_row_font_color(0) #returns font color for first row
48
+ workbook[0].is_row_underlined(0) #returns if first row is italicized, other boolean properties have same syntax
49
+ workbook[0].get_row_height(0) #returns height of first row
50
+ workbook[0].get_row_horizontal_alignment(0) #returns horizontal alignment of first row (nil if none exists)
51
+ workbook[0].get_row_vertical_alignment(0) #returns vertical alignment of first row (nil if none exists)
52
+ workbook[0].get_row_border_right(0) #returns weight of right border of first row (nil if none exists), other directions have the same syntax
53
+
54
+ ==== Accessing column properties
55
+ workbook[0].get_column_fill(0) #returns fill color for first column
56
+ workbook[0].get_column_font_name(0) #returns font name for first column
57
+ workbook[0].get_column_font_size(0) #returns font size for first column
58
+ workbook[0].get_column_font_color(0) #returns font color for first column
59
+ workbook[0].is_column_underlined(0) #returns if first column is italicized, other boolean properties have same syntax
60
+ workbook[0].get_column_height(0) #returns height of first column
61
+ workbook[0].get_column_horizontal_alignment(0) #returns horizontal alignment of first column (nil if none exists)
62
+ workbook[0].get_column_vertical_alignment(0) #returns vertical alignment of first column (nil if none exists)
63
+ workbook[0].get_column_border_right(0) #returns weight of right border of first column (nil if none exists), other directions have the same syntax
64
+
65
+ ==== Table identification
66
+ workbook[0].get_table(["NAME", "AGE", "HEIGHT"]) #returns hash of a table in the first worksheet, with the specified strings as headers, accessible by row and column
67
+ #it returns the following structure
68
+ {
69
+ :Name=>["John", "Jane", "Joe"],
70
+ :Height=>[70, 65, 68],
71
+ :Age=>[30, 25, 35]
72
+ :table=>[
73
+ {:Name=>"John", :Height=>70, :Age=>30},
74
+ {:Name=>"Jane", :Height=>65, :Age=>25},
75
+ {:Name=>"Joe", :Height=>68, :Age=>35}
76
+ ]
77
+ }
78
+
79
+ === Modifying
80
+
81
+ ==== Adding Worksheets
82
+ workbook.worksheets << Worksheet.new('Sheet2')
83
+
84
+ ==== Adding Cells
85
+ workbook.worksheets[0].add_cell(0,0,'A1') #sets A1 to string "A1"
86
+ workbook.worksheets[0].add_cell(0,1,'','A1') #sets B1 to value of A1
87
+
88
+ workbook.worksheets[0].add_cell_obj(Cell.new(1,0,'blah')) #sets A2 to 'blah'
89
+
90
+ ==== Changing Cells
91
+ workbook.worksheets[0][0][0].change_contents("", workbook.worksheets[0][0][0].formula) #sets A1 to empty string, preserves formula
92
+
93
+ ==== Changing Fonts
94
+ workbook.worksheets[0].sheet_data[0][0].change_font_bold(true) #sets A1 to bold
95
+ workbook.worksheets[0].change_row_font_italics(0,true) #makes first row italicized
96
+ workbook.worksheets[0].change_column_font_name(0,'Courier') #makes first column have font Courier
97
+
98
+ ==== Changing Fills
99
+ workbook.worksheets[0].sheet_data[0][0].change_fill('0ba53d') #sets A1 to have fill #0ba53d
100
+ workbook.worksheets[0].change_row_fill(0, '0ba53d') #sets first row to have fill #0ba53d
101
+ workbook.worksheets[0].change_column_fill(0, '0ba53d') #sets first column to have fill #0ba53d
102
+
103
+ ==== Changing Borders
104
+ # Possible weights: hairline, thin, medium, thick
105
+ # Possible "directions": top, bottom, left, right, diagonal
106
+ workbook.worksheets[0].sheet_data[0][0].change_border_top('thin') #sets A1 to have a top, thin border
107
+ workbook.worksheets[0].change_row_border_left(0, 'hairline') #sets first row to have a left, hairline border
108
+ workbook.worksheets[0].change_column_border_diagonal(0, 'medium') #sets first column to have diagonal, medium border
109
+
110
+ ==== Changing Alignment
111
+ ===== Horizontal
112
+ center, distributed, justify, left, right
113
+ workbook.worksheets[0].sheet_data[0][0].change_horizontal_alignment('center') #sets A1 to be centered
114
+ workbook.worksheets[0].change_row_horizontal_alignment(0,'justify') #sets first row to be justified
115
+ workbook.worksheets[0].change_column_horizontal_alignment(0,'right'), #sets first column to be right-aligned
116
+
117
+ ===== Vertical
118
+ bottom, center, distributed, top
119
+ workbook.worksheets[0].sheet_data[0][0].change_vertical_alignment('bottom') #sets A1 to be bottom aligned
120
+ workbook.worksheets[0].change_row_vertical_alignment(0,'distributed') #sets first row to be distributed vertically
121
+ workbook.worksheets[0].change_column_vertical_alignment(0,'top') #sets first column to be top aligned
122
+
123
+ ==== Changing Row Height
124
+ workbook.worksheets[0].change_row_height(0,30) #sets first row to be of height 30
125
+
126
+ ==== Changing Column Width
127
+ workbook.worksheets[0].change_column_width(0,30) #sets first column to be of width 30
128
+
129
+ ==== Merging Cells
130
+ workbook.worksheets[0].merge_cells(0,0,1,1) #merges A1:B2
131
+
132
+ ==== Insert Row
133
+ This method will insert a row at specified index, pushing all rows below it down. It also copies styles from row above.
134
+
135
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted rows
136
+ workbook.worksheets[0].insert_row(1)
137
+
138
+ ==== Insert Column
139
+ This method will insert a column at specified index, pushing all columns to the right of it one to the right. It also copies styles from column to the left
140
+
141
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted columns
142
+ workbook.worksheets[0].insert_column(1)
143
+
144
+ ==== Delete Row
145
+ This method will delete a row at specified index, pushing all rows below it up.
146
+
147
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted rows
148
+ workbook.worksheets[0].delete_row(1)
149
+
150
+ ==== Delete Column
151
+ This method will delete a column at specified index, pushing all columns to the right of it left.
152
+
153
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted columns
154
+ workbook.worksheets[0].delete_column(1)
155
+
156
+ ==== Insert Cell
157
+ This method will insert a cell at specified position. It takes a :right or :down option, to shift cells either left or down upon inserting (nil means replacing the cell)
158
+
159
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted cells
160
+ workbook.worksheets[0].insert_cell(0,0,"blah",formula=nil,:right) #inserts cell at A1, shifts cells in first row right
161
+ workbook.worksheets[0].insert_cell(0,0,"blah",formula=nil,:down) #inserts cell at A1, shifts cells in first column down
162
+ workbook.worksheets[0].insert_cell(0,0,"blah") #inserts cell at A1, shifts nothing
163
+
164
+ ==== Delete Cell
165
+ This method will delete a cell at specified position. It takes a :left or :up option, to shift cells either up or left upon deletion (nil means simply deleting the cell contents)
166
+
167
+ WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted cells
168
+ workbook.worksheets[0].delete_cell(0,0,:left) #deletes A1, shifts contents of first row left
169
+ workbook.worksheets[0].delete_cell(0,0,:up) #deletes A1, shifts contents of first column up
170
+ workbook.worksheets[0].delete_cell(0,0) #deletes A1, does not shift cells
171
+
172
+ === Writing
173
+ workbook.write("path/to/desired/Excel/file.xlsx")
174
+
175
+
176
+ === Miscellaneous
177
+ Cell.convert_to_cell(0,0) == 'A1' #converts row and column index to Excel-style index
178
+ Parser.convert_to_index('A1') == [0,0] #converts Excel-style index to row and column index
179
+
180
+ == For more information
181
+ Take a look at the files in spec/lib/ for rspecs on most methods
182
+
183
+ == Contributing to rubyXL
184
+
185
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
186
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
187
+ * Fork the project
188
+ * Start a feature/bugfix branch
189
+ * Commit and push until you are happy with your contribution
190
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
191
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
192
+
193
+ == Copyright
194
+
195
+ Copyright (c) 2011 Vivek Bhagwat. See LICENSE.txt for
196
+ further details.
197
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rubyXL"
18
+ gem.homepage = "http://github.com/gilt/rubyXL"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
21
+ gem.description = %Q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
22
+ gem.email = "bhagwat.vivek@gmail.com"
23
+ gem.authors = ["Vivek Bhagwat"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rubyXL #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.10
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ # modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
4
+
5
+ module RubyXL
6
+ # class Hash
7
+ class Hash < ::Hash
8
+ def self.from_xml(xml_io)
9
+ begin
10
+ result = Nokogiri::XML(xml_io)
11
+ return { result.root.name.to_sym => xml_node_to_hash(result.root)}
12
+ rescue Exception => e
13
+ # raise your custom exception here
14
+ end
15
+ end
16
+
17
+ def self.xml_node_to_hash(node)
18
+ # If we are at the root of the document, start the hash
19
+ if node.element?
20
+ result_hash = {}
21
+ if node.attributes != {}
22
+ result_hash[:attributes] = {}
23
+ node.attributes.keys.each do |key|
24
+ result_hash[:attributes][node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
25
+ end
26
+ end
27
+ if node.children.size > 0
28
+ node.children.each do |child|
29
+ result = xml_node_to_hash(child)
30
+
31
+ if child.name == "text"
32
+ unless child.next_sibling || child.previous_sibling
33
+ return prepare(result)
34
+ end
35
+ elsif result_hash[child.name.to_sym]
36
+ if result_hash[child.name.to_sym].is_a?(Object::Array)
37
+ result_hash[child.name.to_sym] << prepare(result)
38
+ else
39
+ result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
40
+ end
41
+ else
42
+ result_hash[child.name.to_sym] = prepare(result)
43
+ end
44
+ end
45
+
46
+ return result_hash
47
+ else
48
+ return result_hash
49
+ end
50
+ else
51
+ return prepare(node.content.to_s)
52
+ end
53
+ end
54
+
55
+ def self.prepare(data)
56
+ (data.class == String && data.to_i.to_s == data) ? data.to_i : data
57
+ end
58
+ end
59
+ # end
60
+ end