openxml-xlsx 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +4 -4
  4. data/example +4 -3
  5. data/lib/openxml-xlsx.rb +1 -0
  6. data/lib/openxml/xlsx.rb +30 -0
  7. data/lib/{xlsx → openxml/xlsx}/elements.rb +4 -2
  8. data/lib/openxml/xlsx/elements/alignment.rb +22 -0
  9. data/lib/openxml/xlsx/elements/border.rb +28 -0
  10. data/lib/openxml/xlsx/elements/border_component.rb +21 -0
  11. data/lib/openxml/xlsx/elements/border_style.rb +22 -0
  12. data/lib/openxml/xlsx/elements/cell.rb +96 -0
  13. data/lib/openxml/xlsx/elements/defined_name.rb +13 -0
  14. data/lib/openxml/xlsx/elements/font.rb +22 -0
  15. data/lib/openxml/xlsx/elements/implied_number_format.rb +7 -0
  16. data/lib/openxml/xlsx/elements/indexed_color.rb +13 -0
  17. data/lib/openxml/xlsx/elements/number_format.rb +47 -0
  18. data/lib/openxml/xlsx/elements/pattern_fill.rb +20 -0
  19. data/lib/openxml/xlsx/elements/relationship.rb +20 -0
  20. data/lib/openxml/xlsx/elements/row.rb +37 -0
  21. data/lib/openxml/xlsx/elements/style.rb +29 -0
  22. data/lib/openxml/xlsx/elements/table_column.rb +8 -0
  23. data/lib/openxml/xlsx/elements/theme_color.rb +13 -0
  24. data/lib/openxml/xlsx/package.rb +52 -0
  25. data/lib/{xlsx → openxml/xlsx}/parts.rb +4 -2
  26. data/lib/openxml/xlsx/parts/shared_strings.rb +28 -0
  27. data/lib/openxml/xlsx/parts/stylesheet.rb +80 -0
  28. data/lib/openxml/xlsx/parts/table.rb +36 -0
  29. data/lib/openxml/xlsx/parts/workbook.rb +71 -0
  30. data/lib/openxml/xlsx/parts/worksheet.rb +90 -0
  31. data/lib/openxml/xlsx/version.rb +5 -0
  32. data/{xlsx.gemspec → openxml-xlsx.gemspec} +5 -5
  33. metadata +37 -36
  34. data/lib/xlsx.rb +0 -28
  35. data/lib/xlsx/elements/alignment.rb +0 -20
  36. data/lib/xlsx/elements/border.rb +0 -26
  37. data/lib/xlsx/elements/border_component.rb +0 -19
  38. data/lib/xlsx/elements/border_style.rb +0 -20
  39. data/lib/xlsx/elements/cell.rb +0 -94
  40. data/lib/xlsx/elements/defined_name.rb +0 -11
  41. data/lib/xlsx/elements/font.rb +0 -20
  42. data/lib/xlsx/elements/implied_number_format.rb +0 -5
  43. data/lib/xlsx/elements/indexed_color.rb +0 -11
  44. data/lib/xlsx/elements/number_format.rb +0 -45
  45. data/lib/xlsx/elements/pattern_fill.rb +0 -18
  46. data/lib/xlsx/elements/relationship.rb +0 -18
  47. data/lib/xlsx/elements/row.rb +0 -35
  48. data/lib/xlsx/elements/style.rb +0 -27
  49. data/lib/xlsx/elements/table_column.rb +0 -6
  50. data/lib/xlsx/elements/theme_color.rb +0 -11
  51. data/lib/xlsx/package.rb +0 -50
  52. data/lib/xlsx/parts/shared_strings.rb +0 -26
  53. data/lib/xlsx/parts/stylesheet.rb +0 -78
  54. data/lib/xlsx/parts/table.rb +0 -34
  55. data/lib/xlsx/parts/workbook.rb +0 -66
  56. data/lib/xlsx/parts/worksheet.rb +0 -88
  57. data/lib/xlsx/version.rb +0 -3
@@ -0,0 +1,5 @@
1
+ module OpenXml
2
+ module Xlsx
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "xlsx/version"
4
+ require "openxml/xlsx/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "openxml-xlsx"
8
- spec.version = Xlsx::VERSION
8
+ spec.version = OpenXml::Xlsx::VERSION
9
9
  spec.authors = ["Bob Lail"]
10
- spec.email = ["bob.lail@cph.org"]
10
+ spec.email = ["bob.lailfamily@gmail.com"]
11
11
 
12
12
  spec.description = %q{Create Microsoft Excel (.xlsx) files.}
13
13
  spec.summary = %q{Using a simple API, create xlsx files programmatically}
14
14
  spec.license = "MIT"
15
- spec.homepage = "https://github.com/concordia-publishing-house/xlsx"
15
+ spec.homepage = "https://github.com/openxml/openxml-xlsx"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  spec.bindir = "exe"
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = "~> 2.0"
23
23
  spec.add_dependency "nokogiri"
24
- spec.add_dependency "open_xml_package", "0.2.0.beta1"
24
+ spec.add_dependency "openxml-package", ">= 0.2.0"
25
25
 
26
26
  spec.add_development_dependency "pry"
27
27
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openxml-xlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: open_xml_package
28
+ name: openxml-package
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0.beta1
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.0.beta1
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: '0'
125
125
  description: Create Microsoft Excel (.xlsx) files.
126
126
  email:
127
- - bob.lail@cph.org
127
+ - bob.lailfamily@gmail.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
@@ -137,34 +137,35 @@ files:
137
137
  - bin/console
138
138
  - bin/setup
139
139
  - example
140
- - lib/xlsx.rb
141
- - lib/xlsx/elements.rb
142
- - lib/xlsx/elements/alignment.rb
143
- - lib/xlsx/elements/border.rb
144
- - lib/xlsx/elements/border_component.rb
145
- - lib/xlsx/elements/border_style.rb
146
- - lib/xlsx/elements/cell.rb
147
- - lib/xlsx/elements/defined_name.rb
148
- - lib/xlsx/elements/font.rb
149
- - lib/xlsx/elements/implied_number_format.rb
150
- - lib/xlsx/elements/indexed_color.rb
151
- - lib/xlsx/elements/number_format.rb
152
- - lib/xlsx/elements/pattern_fill.rb
153
- - lib/xlsx/elements/relationship.rb
154
- - lib/xlsx/elements/row.rb
155
- - lib/xlsx/elements/style.rb
156
- - lib/xlsx/elements/table_column.rb
157
- - lib/xlsx/elements/theme_color.rb
158
- - lib/xlsx/package.rb
159
- - lib/xlsx/parts.rb
160
- - lib/xlsx/parts/shared_strings.rb
161
- - lib/xlsx/parts/stylesheet.rb
162
- - lib/xlsx/parts/table.rb
163
- - lib/xlsx/parts/workbook.rb
164
- - lib/xlsx/parts/worksheet.rb
165
- - lib/xlsx/version.rb
166
- - xlsx.gemspec
167
- homepage: https://github.com/concordia-publishing-house/xlsx
140
+ - lib/openxml-xlsx.rb
141
+ - lib/openxml/xlsx.rb
142
+ - lib/openxml/xlsx/elements.rb
143
+ - lib/openxml/xlsx/elements/alignment.rb
144
+ - lib/openxml/xlsx/elements/border.rb
145
+ - lib/openxml/xlsx/elements/border_component.rb
146
+ - lib/openxml/xlsx/elements/border_style.rb
147
+ - lib/openxml/xlsx/elements/cell.rb
148
+ - lib/openxml/xlsx/elements/defined_name.rb
149
+ - lib/openxml/xlsx/elements/font.rb
150
+ - lib/openxml/xlsx/elements/implied_number_format.rb
151
+ - lib/openxml/xlsx/elements/indexed_color.rb
152
+ - lib/openxml/xlsx/elements/number_format.rb
153
+ - lib/openxml/xlsx/elements/pattern_fill.rb
154
+ - lib/openxml/xlsx/elements/relationship.rb
155
+ - lib/openxml/xlsx/elements/row.rb
156
+ - lib/openxml/xlsx/elements/style.rb
157
+ - lib/openxml/xlsx/elements/table_column.rb
158
+ - lib/openxml/xlsx/elements/theme_color.rb
159
+ - lib/openxml/xlsx/package.rb
160
+ - lib/openxml/xlsx/parts.rb
161
+ - lib/openxml/xlsx/parts/shared_strings.rb
162
+ - lib/openxml/xlsx/parts/stylesheet.rb
163
+ - lib/openxml/xlsx/parts/table.rb
164
+ - lib/openxml/xlsx/parts/workbook.rb
165
+ - lib/openxml/xlsx/parts/worksheet.rb
166
+ - lib/openxml/xlsx/version.rb
167
+ - openxml-xlsx.gemspec
168
+ homepage: https://github.com/openxml/openxml-xlsx
168
169
  licenses:
169
170
  - MIT
170
171
  metadata: {}
data/lib/xlsx.rb DELETED
@@ -1,28 +0,0 @@
1
- module Xlsx
2
- REL_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument".freeze
3
- REL_WORKSHEET = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet".freeze
4
- REL_STYLES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles".freeze
5
- REL_SHARED_STRINGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings".freeze
6
- REL_CALC_CHAIN = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain".freeze
7
- REL_THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme".freeze
8
- REL_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table".freeze
9
-
10
- TYPE_WORKBOOK = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml".freeze
11
- TYPE_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
12
- TYPE_THEME = "application/vnd.openxmlformats-officedocument.theme+xml".freeze
13
- TYPE_STYLES = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml".freeze
14
- TYPE_SHARED_STRINGS = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml".freeze
15
- TYPE_CALC_CHAIN = "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml".freeze
16
- TYPE_CORE_PROPS = "application/vnd.openxmlformats-package.core-properties+xml".freeze
17
- TYPE_APP_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml".freeze
18
- TYPE_TABLE = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml".freeze
19
-
20
- def self.index!(collection, item)
21
- collection.index(item) || collection.push(item).length - 1
22
- end
23
-
24
- end
25
-
26
- require "xlsx/elements"
27
- require "xlsx/package"
28
- require "xlsx/parts"
@@ -1,20 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class Alignment < Struct.new(:horizontal, :vertical, :indent, :wrapText)
4
-
5
- def attributes
6
- {}.tap do |attrs|
7
- attrs[:horizontal] = horizontal if horizontal
8
- attrs[:vertical] = vertical if vertical
9
- attrs[:indent] = indent if indent
10
- attrs[:wrapText] = wrapText if wrapText
11
- end
12
- end
13
-
14
- def to_xml(xml)
15
- xml.alignment(attributes)
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class Border
4
- attr_reader :left_component, :right_component, :top_component, :bottom_component, :diagonal_component
5
-
6
- def initialize(options={})
7
- @left_component = options.fetch(:left, BorderComponent.new)
8
- @right_component = options.fetch(:right, BorderComponent.new)
9
- @top_component = options.fetch(:top, BorderComponent.new)
10
- @bottom_component = options.fetch(:bottom, BorderComponent.new)
11
- @diagonal_component = options.fetch(:diagonal, BorderComponent.new)
12
- end
13
-
14
- def to_xml(xml)
15
- xml.border do
16
- left_component.to_xml("left", xml)
17
- right_component.to_xml("right", xml)
18
- top_component.to_xml("top", xml)
19
- bottom_component.to_xml("bottom", xml)
20
- diagonal_component.to_xml("diagonal", xml)
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1,19 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class BorderComponent < Struct.new(:style, :color)
4
-
5
- def to_xml(name, xml)
6
- if style && color
7
- xml.public_send(name, style: style) do
8
- color.to_xml("color", xml)
9
- end
10
- elsif style
11
- xml.public_send(name, style: style)
12
- else
13
- xml.public_send(name)
14
- end
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,20 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class BorderStyle
4
- NONE = "none".freeze
5
- THIN = "thin".freeze
6
- MEDIUM = "medium".freeze
7
- DASHED = "dashed".freeze
8
- DOTTED = "dotted".freeze
9
- THICK = "thick".freeze
10
- DOUBLE = "double".freeze
11
- HAIR = "hair".freeze
12
- MEDIUM_DASHED = "mediumDashed".freeze
13
- DASH_DOT = "dashDot".freeze
14
- MEDIUM_DASH_DOT = "mediumDashDot".freeze
15
- DASH_DOT_DOT = "dashDotDot".freeze
16
- MEDIUM_DASH_DOT_DOT = "mediumDashDotDot".freeze
17
- SLANT_DASH_DOT = "slantDashDot".freeze
18
- end
19
- end
20
- end
@@ -1,94 +0,0 @@
1
- require "date"
2
-
3
- module Xlsx
4
- module Elements
5
- class Cell
6
- attr_reader :row, :column, :value, :type, :style, :formula
7
-
8
- def initialize(row, options={})
9
- @row = row
10
- @column = options.fetch(:column)
11
- @value = options[:value]
12
- case value
13
- when String
14
- @type = :string
15
- @string_id = package.string_ref(value)
16
- when Date then
17
- @type = :date
18
- @serial_date = to_serial_date(value)
19
- when Time then
20
- @type = :time
21
- @serial_time = to_serial_time(value)
22
- else
23
- @type = :general
24
- end
25
- @style = package.style_ref(options[:style]) if options.key? :style
26
- @formula = options[:formula]
27
- end
28
-
29
- def id
30
- "#{column_letter}#{row.number}"
31
- end
32
-
33
- def column_letter
34
- bytes = []
35
- remaining = column
36
- while remaining > 0
37
- bytes.unshift (remaining - 1) % 26 + 65
38
- remaining = (remaining - 1) / 26
39
- end
40
- bytes.pack "c*"
41
- end
42
-
43
- def worksheet
44
- row.worksheet
45
- end
46
-
47
- def workbook
48
- worksheet.workbook
49
- end
50
-
51
- def package
52
- workbook.package
53
- end
54
-
55
- def to_xml(xml)
56
- attributes = {"r" => id}
57
- attributes.merge!("s" => style) if style
58
- attributes.merge!("t" => "s") if type == :string
59
-
60
- value = self.value
61
- value = string_id if type == :string
62
- value = serial_date if type == :date
63
- value = serial_time if type == :time
64
-
65
- xml.c(attributes) do
66
- xml.f formula if formula
67
- xml.v value if value
68
- end
69
- end
70
-
71
- private
72
- attr_reader :string_id, :serial_date, :serial_time
73
-
74
- EXCEL_ANCHOR_DATE = Date.new(1900, 1, 1).freeze
75
- SECONDS_PER_DAY = 86400.freeze
76
-
77
- def to_serial_date(date)
78
- # Excel stores dates as the number of days since 1900-Jan-0
79
- # Excel behaves as if 1900 was a leap year, so the number is
80
- # generally 1 greater than you would expect.
81
- # http://www.cpearson.com/excel/datetime.htm
82
- (date - EXCEL_ANCHOR_DATE).to_i + 2
83
- end
84
-
85
- def to_serial_time(time)
86
- date = to_serial_date(time.to_date)
87
-
88
- seconds_since_midnight = time.hour * 3600 + time.min * 60 + time.sec
89
- date + (seconds_since_midnight.to_f / SECONDS_PER_DAY)
90
- end
91
-
92
- end
93
- end
94
- end
@@ -1,11 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class DefinedName < Struct.new(:name, :formula)
4
-
5
- def to_xml(xml)
6
- xml.definedName "#{formula}", name: name
7
- end
8
-
9
- end
10
- end
11
- end
@@ -1,20 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class Font < Struct.new(:name, :size, :styles)
4
-
5
- def to_xml(xml)
6
- xml.font do
7
- xml.sz val: size
8
- xml.name val: name
9
- if styles
10
- xml.b if styles[:bold]
11
- xml.i if styles[:italic]
12
- xml.u if styles[:underline]
13
- styles[:color].to_xml("color", xml) if styles[:color]
14
- end
15
- end
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- ImpliedNumberFormat = Struct.new(:id)
4
- end
5
- end
@@ -1,11 +0,0 @@
1
- module Xlsx
2
- module Elements
3
- class IndexedColor < Struct.new(:indexed)
4
-
5
- def to_xml(name, xml)
6
- xml.public_send(name, indexed: indexed)
7
- end
8
-
9
- end
10
- end
11
- end
@@ -1,45 +0,0 @@
1
- require "xlsx/elements/implied_number_format"
2
-
3
- module Xlsx
4
- module Elements
5
- class NumberFormat < Struct.new(:format)
6
- INTEGER = ImpliedNumberFormat.new(1).freeze # 0
7
- DECIMAL = ImpliedNumberFormat.new(2).freeze # 0.00
8
- INTEGER_THOUSANDS = ImpliedNumberFormat.new(3).freeze # #,##0
9
- DECIMAL_THOUSANDS = ImpliedNumberFormat.new(4).freeze # #,##0.00
10
-
11
- INTEGER_PERCENT = ImpliedNumberFormat.new(9).freeze # 0%
12
- DECIMAL_PERCENT = ImpliedNumberFormat.new(10).freeze # 0.00%
13
- SCIENTIFIC = ImpliedNumberFormat.new(11).freeze # 0.00E+00
14
- FRACTION = ImpliedNumberFormat.new(12).freeze # ?/?
15
- FRACTION2 = ImpliedNumberFormat.new(13).freeze # ??/??
16
- DATE = ImpliedNumberFormat.new(14).freeze # mm-dd-yy
17
- DATE_ALT = ImpliedNumberFormat.new(15).freeze # d-mmm-yy
18
- DAY_MONTH = ImpliedNumberFormat.new(16).freeze # d-mmm
19
- MONTH_YEAR = ImpliedNumberFormat.new(17).freeze # mmm-yy
20
- TIME = ImpliedNumberFormat.new(18).freeze # h:mm AM/PM
21
- TIME_SECONDS = ImpliedNumberFormat.new(19).freeze # h:mm:ss AM/PM
22
- TIME_ALT = ImpliedNumberFormat.new(20).freeze # h:mm
23
- TIME_SECONDS_ALT = ImpliedNumberFormat.new(21).freeze # h:mm:ss
24
- DATETIME = ImpliedNumberFormat.new(22).freeze # m/d/yy h:mm
25
-
26
- FINANCIAL_INTEGER = ImpliedNumberFormat.new(37).freeze # #,##0 ;(#,##0)
27
- FINANCIAL_INTEGER_RED = ImpliedNumberFormat.new(38).freeze # #,##0 ;[Red](#,##0)
28
- FINANCIAL_DECIMAL = ImpliedNumberFormat.new(39).freeze # #,##0.00 ;(#,##0.00)
29
- FINANCIAL_DECIMAL_RED = ImpliedNumberFormat.new(40).freeze # #,##0.00 ;[Red](#,##0.00)
30
-
31
- INTERVAL = ImpliedNumberFormat.new(45).freeze # mm:ss
32
- INTERVAL_HOURS = ImpliedNumberFormat.new(46).freeze # [h]:mm:ss
33
- TIMESTAMP = ImpliedNumberFormat.new(47).freeze # mmss.0
34
- # SCIENTIFIC_ALT = ImpliedNumberFormat.new(48).freeze # ##0.0E+0
35
- # UNKONWN = ImpliedNumberFormat.new(49).freeze # @
36
-
37
-
38
-
39
- def to_xml(id, xml)
40
- xml.numFmt(numFmtId: id, formatCode: format)
41
- end
42
-
43
- end
44
- end
45
- end