rubyXL-git-ref-6002046 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +20 -0
  3. data/Gemfile.lock +63 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +197 -0
  6. data/Rakefile +58 -0
  7. data/VERSION +1 -0
  8. data/lib/rubyXL.rb +21 -0
  9. data/lib/rubyXL/cell.rb +325 -0
  10. data/lib/rubyXL/generic_storage.rb +40 -0
  11. data/lib/rubyXL/objects/border.rb +53 -0
  12. data/lib/rubyXL/objects/cell_style.rb +73 -0
  13. data/lib/rubyXL/objects/color.rb +23 -0
  14. data/lib/rubyXL/objects/column_range.rb +88 -0
  15. data/lib/rubyXL/objects/data_validation.rb +31 -0
  16. data/lib/rubyXL/objects/defined_name.rb +27 -0
  17. data/lib/rubyXL/objects/fill.rb +42 -0
  18. data/lib/rubyXL/objects/font.rb +109 -0
  19. data/lib/rubyXL/objects/formula.rb +8 -0
  20. data/lib/rubyXL/objects/ooxml_object.rb +177 -0
  21. data/lib/rubyXL/objects/reference.rb +98 -0
  22. data/lib/rubyXL/objects/sheet_view.rb +62 -0
  23. data/lib/rubyXL/objects/worksheet.rb +11 -0
  24. data/lib/rubyXL/parser.rb +307 -0
  25. data/lib/rubyXL/private_class.rb +95 -0
  26. data/lib/rubyXL/shared_strings.rb +35 -0
  27. data/lib/rubyXL/workbook.rb +342 -0
  28. data/lib/rubyXL/worksheet.rb +1118 -0
  29. data/lib/rubyXL/writer/app_writer.rb +51 -0
  30. data/lib/rubyXL/writer/calc_chain_writer.rb +18 -0
  31. data/lib/rubyXL/writer/content_types_writer.rb +113 -0
  32. data/lib/rubyXL/writer/core_writer.rb +34 -0
  33. data/lib/rubyXL/writer/generic_writer.rb +33 -0
  34. data/lib/rubyXL/writer/root_rels_writer.rb +17 -0
  35. data/lib/rubyXL/writer/shared_strings_writer.rb +21 -0
  36. data/lib/rubyXL/writer/styles_writer.rb +64 -0
  37. data/lib/rubyXL/writer/theme_writer.rb +337 -0
  38. data/lib/rubyXL/writer/workbook_rels_writer.rb +43 -0
  39. data/lib/rubyXL/writer/workbook_writer.rb +73 -0
  40. data/lib/rubyXL/writer/worksheet_writer.rb +164 -0
  41. data/lib/rubyXL/zip.rb +20 -0
  42. data/rdoc/created.rid +36 -0
  43. data/rdoc/fonts.css +167 -0
  44. data/rdoc/fonts/Lato-Light.ttf +0 -0
  45. data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
  46. data/rdoc/fonts/Lato-Regular.ttf +0 -0
  47. data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
  48. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  49. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  50. data/rdoc/images/add.png +0 -0
  51. data/rdoc/images/arrow_up.png +0 -0
  52. data/rdoc/images/brick.png +0 -0
  53. data/rdoc/images/brick_link.png +0 -0
  54. data/rdoc/images/bug.png +0 -0
  55. data/rdoc/images/bullet_black.png +0 -0
  56. data/rdoc/images/bullet_toggle_minus.png +0 -0
  57. data/rdoc/images/bullet_toggle_plus.png +0 -0
  58. data/rdoc/images/date.png +0 -0
  59. data/rdoc/images/delete.png +0 -0
  60. data/rdoc/images/find.png +0 -0
  61. data/rdoc/images/loadingAnimation.gif +0 -0
  62. data/rdoc/images/macFFBgHack.png +0 -0
  63. data/rdoc/images/package.png +0 -0
  64. data/rdoc/images/page_green.png +0 -0
  65. data/rdoc/images/page_white_text.png +0 -0
  66. data/rdoc/images/page_white_width.png +0 -0
  67. data/rdoc/images/plugin.png +0 -0
  68. data/rdoc/images/ruby.png +0 -0
  69. data/rdoc/images/tag_blue.png +0 -0
  70. data/rdoc/images/tag_green.png +0 -0
  71. data/rdoc/images/transparent.png +0 -0
  72. data/rdoc/images/wrench.png +0 -0
  73. data/rdoc/images/wrench_orange.png +0 -0
  74. data/rdoc/images/zoom.png +0 -0
  75. data/rdoc/js/darkfish.js +140 -0
  76. data/rdoc/js/jquery.js +18 -0
  77. data/rdoc/js/navigation.js +142 -0
  78. data/rdoc/js/search.js +109 -0
  79. data/rdoc/js/search_index.js +1 -0
  80. data/rdoc/js/searcher.js +228 -0
  81. data/rdoc/rdoc.css +580 -0
  82. data/rubyXL-git-ref-6002046.gemspec +143 -0
  83. data/spec/lib/cell_spec.rb +407 -0
  84. data/spec/lib/color_spec.rb +14 -0
  85. data/spec/lib/parser_spec.rb +80 -0
  86. data/spec/lib/workbook_spec.rb +73 -0
  87. data/spec/lib/worksheet_spec.rb +1789 -0
  88. metadata +231 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20bfad55d757e0c11501fe38070242bc26ce9459
4
+ data.tar.gz: 5cc647d9eb227eb7deba27d004badce4706a3b43
5
+ SHA512:
6
+ metadata.gz: 8956b9cf6c5013a2f1f754bf1bd947efd276f9c94646f8d1ddfba83cda1e1606c129ce46519377f89b22582b32126919c8baa721554f457ba20229d4992abc9a
7
+ data.tar.gz: a086acc2c0e344314d0e9f6612b3e9dc1fa8d2ce0942936701556b98792eaa9ff0f28b07484ba1eee00c6a6776c374e00dc56ea2c29b5c3fb055423c064f4cf2
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Dependencies required to run this gem.
4
+ gem "nokogiri", ">= 1.4.4"
5
+ gem "rubyzip", ">= 1.0.0"
6
+
7
+ # Development dependencies.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler"
11
+ gem "jeweler"
12
+
13
+ if RUBY_VERSION =~ /^1\.9/
14
+ gem "simplecov", ">= 0"
15
+ else
16
+ gem "rcov", ">= 0"
17
+ end
18
+
19
+ gem "rspec", ">= 1.3.4"
20
+ end
@@ -0,0 +1,63 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.2)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ atomic (1.1.14)
11
+ diff-lcs (1.2.5)
12
+ docile (1.1.1)
13
+ git (1.2.6)
14
+ i18n (0.6.9)
15
+ jeweler (1.8.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rdoc
20
+ json (1.8.1)
21
+ mini_portile (0.5.2)
22
+ minitest (4.7.5)
23
+ multi_json (1.8.2)
24
+ nokogiri (1.6.1)
25
+ mini_portile (~> 0.5.0)
26
+ rake (10.1.1)
27
+ rdoc (4.1.0)
28
+ json (~> 1.4)
29
+ rspec (2.14.1)
30
+ rspec-core (~> 2.14.0)
31
+ rspec-expectations (~> 2.14.0)
32
+ rspec-mocks (~> 2.14.0)
33
+ rspec-core (2.14.7)
34
+ rspec-expectations (2.14.4)
35
+ diff-lcs (>= 1.1.3, < 2.0)
36
+ rspec-mocks (2.14.4)
37
+ rubyzip (1.1.0)
38
+ shoulda (3.5.0)
39
+ shoulda-context (~> 1.0, >= 1.0.1)
40
+ shoulda-matchers (>= 1.4.1, < 3.0)
41
+ shoulda-context (1.1.6)
42
+ shoulda-matchers (2.4.0)
43
+ activesupport (>= 3.0.0)
44
+ simplecov (0.8.2)
45
+ docile (~> 1.1.0)
46
+ multi_json
47
+ simplecov-html (~> 0.8.0)
48
+ simplecov-html (0.8.0)
49
+ thread_safe (0.1.3)
50
+ atomic
51
+ tzinfo (0.3.38)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler
58
+ jeweler
59
+ nokogiri (>= 1.4.4)
60
+ rspec (>= 1.3.4)
61
+ rubyzip (>= 1.0.0)
62
+ shoulda
63
+ simplecov
@@ -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.
@@ -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.add_worksheet('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.ind2ref(0,0) == 'A1' # Converts row and column index to Excel-style cell reference
178
+ Cell.ref2ind('A1') == [0,0] # Converts Excel-style cell reference 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
+
@@ -0,0 +1,58 @@
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
+ =begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ =end
44
+
45
+ require 'rspec/core/rake_task'
46
+ RSpec::Core::RakeTask.new(:spec)
47
+
48
+ task :default => :spec
49
+
50
+ require 'rdoc/task'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "rubyXL #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ require 'rubyXL/workbook'
2
+ require 'rubyXL/private_class'
3
+ require 'rubyXL/worksheet'
4
+ require 'rubyXL/cell'
5
+ require 'rubyXL/objects/ooxml_object'
6
+ require 'rubyXL/objects/reference'
7
+ require 'rubyXL/objects/column_range'
8
+ require 'rubyXL/objects/color'
9
+ require 'rubyXL/objects/fill'
10
+ require 'rubyXL/objects/border'
11
+ require 'rubyXL/objects/defined_name'
12
+ require 'rubyXL/objects/font'
13
+ require 'rubyXL/objects/cell_style'
14
+ require 'rubyXL/objects/sheet_view'
15
+ require 'rubyXL/objects/formula'
16
+ require 'rubyXL/objects/data_validation'
17
+ require 'rubyXL/objects/worksheet'
18
+ require 'rubyXL/parser'
19
+
20
+ module RubyXL
21
+ end
@@ -0,0 +1,325 @@
1
+ module RubyXL
2
+ class Cell < PrivateClass
3
+ SHARED_STRING = 's'
4
+ RAW_STRING = 'str'
5
+ ERROR = 'e'
6
+
7
+ attr_accessor :row, :column, :datatype, :style_index, :formula, :worksheet
8
+ attr_reader :workbook,:formula_attributes
9
+
10
+ def initialize(worksheet, row, column, value = nil, formula = nil, datatype = SHARED_STRING, style_index = 0, fmla_attr = {})
11
+ @worksheet = worksheet
12
+
13
+ @workbook = worksheet.workbook
14
+ @row = row
15
+ @column = column
16
+ @datatype = datatype
17
+ @value = value
18
+ @formula=formula
19
+ @style_index = style_index
20
+ @formula_attributes = fmla_attr
21
+ end
22
+
23
+ def value(args = {})
24
+ raw_values = args.delete(:raw) || false
25
+ return @value if raw_values
26
+ return @workbook.num_to_date(@value) if is_date?
27
+ @value
28
+ end
29
+
30
+ def is_date?
31
+ return false if @value.is_a?(String)
32
+ tmp_num_fmt = @workbook.num_fmts_by_id[Integer(get_cell_xf.num_fmt_id)]
33
+ num_fmt = tmp_num_fmt && tmp_num_fmt.format_code
34
+ num_fmt && workbook.date_num_fmt?(num_fmt)
35
+ end
36
+
37
+ # changes fill color of cell
38
+ def change_fill(rgb='ffffff')
39
+ validate_worksheet
40
+ Color.validate_color(rgb)
41
+ @style_index = modify_fill(@workbook, @style_index,rgb)
42
+ end
43
+
44
+ # Changes font name of cell
45
+ def change_font_name(new_font_name = 'Verdana')
46
+ validate_worksheet
47
+
48
+ font = get_cell_font.dup
49
+ font.set_name(new_font_name)
50
+ update_font_references(font)
51
+ end
52
+
53
+ # Changes font size of cell
54
+ def change_font_size(font_size=10)
55
+ validate_worksheet
56
+ raise 'Argument must be a number' unless font_size.is_a?(Integer) || font_size.is_a?(Float)
57
+
58
+ font = get_cell_font.dup
59
+ font.set_size(font_size)
60
+ update_font_references(font)
61
+ end
62
+
63
+ # Changes font color of cell
64
+ def change_font_color(font_color='000000')
65
+ validate_worksheet
66
+ Color.validate_color(font_color)
67
+
68
+ font = get_cell_font.dup
69
+ font.set_rgb_color(font_color)
70
+ update_font_references(font)
71
+ end
72
+
73
+ # Changes font italics settings of cell
74
+ def change_font_italics(italicized=false)
75
+ validate_worksheet
76
+
77
+ font = get_cell_font.dup
78
+ font.set_italic(italicized)
79
+ update_font_references(font)
80
+ end
81
+
82
+ # Changes font bold settings of cell
83
+ def change_font_bold(bolded=false)
84
+ validate_worksheet
85
+
86
+ font = get_cell_font.dup
87
+ font.set_bold(bolded)
88
+ update_font_references(font)
89
+ end
90
+
91
+ # Changes font underline settings of cell
92
+ def change_font_underline(underlined=false)
93
+ validate_worksheet
94
+
95
+ font = get_cell_font.dup
96
+ font.set_underline(underlined)
97
+ update_font_references(font)
98
+ end
99
+
100
+ def change_font_strikethrough(struckthrough=false)
101
+ validate_worksheet
102
+
103
+ font = get_cell_font.dup
104
+ font.set_strikethrough(struckthrough)
105
+ update_font_references(font)
106
+ end
107
+
108
+ # Helper method to update the font array and xf array
109
+ def update_font_references(modified_font)
110
+ xf = @workbook.register_new_font(modified_font, get_cell_xf)
111
+ @style_index = workbook.register_new_xf(xf, @style_index)
112
+ end
113
+
114
+ # changes horizontal alignment of cell
115
+ def change_horizontal_alignment(alignment='center')
116
+ validate_worksheet
117
+ validate_horizontal_alignment(alignment)
118
+ @style_index = modify_alignment(@workbook,@style_index,true,alignment)
119
+ end
120
+
121
+ # changes vertical alignment of cell
122
+ def change_vertical_alignment(alignment='center')
123
+ validate_worksheet
124
+ validate_vertical_alignment(alignment)
125
+ @style_index = modify_alignment(@workbook,@style_index,false,alignment)
126
+ end
127
+
128
+ # changes wrap of cell
129
+ def change_text_wrap(wrap=false)
130
+ validate_worksheet
131
+ validate_text_wrap(wrap)
132
+ @style_index = modify_text_wrap(@workbook,@style_index,wrap)
133
+ end
134
+
135
+ # changes top border of cell
136
+ def change_border_top(weight='thin')
137
+ change_border(:top, weight)
138
+ end
139
+
140
+ # changes left border of cell
141
+ def change_border_left(weight='thin')
142
+ change_border(:left, weight)
143
+ end
144
+
145
+ # changes right border of cell
146
+ def change_border_right(weight='thin')
147
+ change_border(:right, weight)
148
+ end
149
+
150
+ # changes bottom border of cell
151
+ def change_border_bottom(weight='thin')
152
+ change_border(:bottom, weight)
153
+ end
154
+
155
+ # changes diagonal border of cell
156
+ def change_border_diagonal(weight='thin')
157
+ change_border(:diagonal, weight)
158
+ end
159
+
160
+ # changes contents of cell, with formula option
161
+ def change_contents(data, formula=nil)
162
+ validate_worksheet
163
+ @datatype = RAW_STRING
164
+
165
+ if data.is_a?(Date) || data.is_a?(DateTime)
166
+ data = @workbook.date_to_num(data)
167
+ end
168
+
169
+ if (data.is_a?Integer) || (data.is_a?Float)
170
+ @datatype = ''
171
+ end
172
+
173
+ @value=data
174
+ @formula=formula
175
+ end
176
+
177
+ # returns if font is italicized
178
+ def is_italicized()
179
+ validate_worksheet
180
+ get_cell_font.is_italic
181
+ end
182
+
183
+ # returns if font is bolded
184
+ def is_bolded()
185
+ validate_worksheet
186
+ get_cell_font.is_bold
187
+ end
188
+
189
+ def is_underlined()
190
+ validate_worksheet
191
+ get_cell_font.is_underlined
192
+ end
193
+
194
+ def is_struckthrough()
195
+ validate_worksheet
196
+ get_cell_font.is_strikethrough
197
+ end
198
+
199
+ def font_name()
200
+ validate_worksheet
201
+ get_cell_font.get_name
202
+ end
203
+
204
+ def font_size()
205
+ validate_worksheet
206
+ get_cell_font.get_size
207
+ end
208
+
209
+ def font_color()
210
+ validate_worksheet
211
+ get_cell_font.get_rgb_color || '000000'
212
+ end
213
+
214
+ # returns cell's fill color
215
+ def fill_color()
216
+ validate_worksheet
217
+ return @workbook.get_fill_color(get_cell_xf)
218
+ end
219
+
220
+ # returns cell's horizontal alignment
221
+ def horizontal_alignment()
222
+ validate_worksheet
223
+ xf_obj = get_cell_xf
224
+ return nil if xf_obj.alignment.nil?
225
+ xf_obj.alignment.horizontal
226
+ end
227
+
228
+ # returns cell's vertical alignment
229
+ def vertical_alignment()
230
+ validate_worksheet
231
+ xf_obj = get_cell_xf
232
+ return nil if xf_obj.alignment.nil?
233
+ xf_obj.alignment.vertical
234
+ end
235
+
236
+ # returns cell's wrap
237
+ def text_wrap()
238
+ validate_worksheet
239
+ xf_obj = get_cell_xf
240
+ return nil if xf_obj.alignment.nil?
241
+ xf_obj.alignment.wrap_text
242
+ end
243
+
244
+ # returns cell's top border
245
+ def border_top()
246
+ return get_border(:top)
247
+ end
248
+
249
+ # returns cell's left border
250
+ def border_left()
251
+ return get_border(:left)
252
+ end
253
+
254
+ # returns cell's right border
255
+ def border_right()
256
+ return get_border(:right)
257
+ end
258
+
259
+ # returns cell's bottom border
260
+ def border_bottom()
261
+ return get_border(:bottom)
262
+ end
263
+
264
+ # returns cell's diagonal border
265
+ def border_diagonal()
266
+ return get_border(:diagonal)
267
+ end
268
+
269
+ def inspect
270
+ str = "(#{@row},#{@column}): #{@value}"
271
+ str += " =#{@formula}" if @formula
272
+ str += ", datatype = #{@datatype}, style_index = #{@style_index}"
273
+ return str
274
+ end
275
+
276
+ private
277
+
278
+ def change_border(direction, weight)
279
+ validate_worksheet
280
+ validate_border(weight)
281
+
282
+ border = get_cell_border.dup
283
+ border.set_edge_style(direction, weight)
284
+
285
+ xf = workbook.register_new_border(border, get_cell_xf)
286
+ @style_index = workbook.register_new_xf(xf, @style_index)
287
+ end
288
+
289
+ def get_border(direction)
290
+ validate_worksheet
291
+ get_cell_border.get_edge_style(direction)
292
+ end
293
+
294
+ def validate_workbook()
295
+ unless @workbook.nil? || @workbook.worksheets.nil?
296
+ @workbook.worksheets.each do |sheet|
297
+ unless sheet.nil? || sheet.sheet_data.nil? || sheet.sheet_data[@row].nil?
298
+ if sheet.sheet_data[@row][@column] == self
299
+ return
300
+ end
301
+ end
302
+ end
303
+ end
304
+ raise "This cell #{self} is not in workbook #{@workbook}"
305
+ end
306
+
307
+ def validate_worksheet()
308
+ return if @worksheet && @worksheet[@row][@column] == self
309
+ raise "This cell #{self} is not in worksheet #{worksheet}"
310
+ end
311
+
312
+ def get_cell_xf
313
+ @workbook.cell_xfs[@style_index]
314
+ end
315
+
316
+ def get_cell_font
317
+ @workbook.fonts[@workbook.cell_xfs[@style_index].font_id]
318
+ end
319
+
320
+ def get_cell_border
321
+ @workbook.borders[get_cell_xf.border_id]
322
+ end
323
+
324
+ end
325
+ end