to_worksheet 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.
File without changes
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ # Load tasks
5
+ Dir.glob('tasks/**/*.rake').each { |r| Rake.application.add_import r }
6
+
7
+ task :test => :spec
@@ -0,0 +1,65 @@
1
+ class Array
2
+
3
+ XML_START = '
4
+ <?xml version="1.0"?>
5
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
6
+ xmlns:o="urn:schemas-microsoft-com:office:office"
7
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
8
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
9
+ xmlns:html="http://www.w3.org/TR/REC-html40">
10
+ <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
11
+ <Version>14.0</Version>
12
+ </DocumentProperties>
13
+ <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
14
+ <AllowPNG/>
15
+ </OfficeDocumentSettings>
16
+ <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
17
+ <WindowHeight>6240</WindowHeight>
18
+ <WindowWidth>10000</WindowWidth>
19
+ <WindowTopX>120</WindowTopX>
20
+ <WindowTopY>140</WindowTopY>
21
+ <ProtectStructure>False</ProtectStructure>
22
+ <ProtectWindows>False</ProtectWindows>
23
+ </ExcelWorkbook>
24
+ '
25
+
26
+ STYLE = '
27
+ <Styles>
28
+ <Style ss:ID="header">
29
+ <Font ss:Bold="1"/>
30
+ </Style>
31
+ </Styles>
32
+ '
33
+
34
+
35
+ def to_worksheet(options = {})
36
+ options = {:style => true, :name => 'Sheet1'}.merge(options)
37
+
38
+ output = XML_START
39
+ output << STYLE if options[:style]
40
+ output << "<Worksheet ss:Name=\"#{options[:name]}\"><Table>"
41
+ output << '<Row ss:StyleID="header">'
42
+
43
+ options[:header].each { |value| output << add_cell(value) } if !options[:header].nil?
44
+
45
+ output << "</Row>"
46
+
47
+ self.each do |array|
48
+ output << "<Row>"
49
+ array.each do |value|
50
+ output << add_cell(value)
51
+ end
52
+ output << "</Row>"
53
+ end
54
+
55
+ output << '</Table></Worksheet></Workbook>'
56
+
57
+ end
58
+
59
+ def add_cell(value)
60
+ "<Cell><Data ss:Type=\"#{value.is_a?(Integer) ? 'Number' : 'String'}\">#{value}</Data></Cell>"
61
+ end
62
+
63
+ end
64
+
65
+
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+
3
+ Dir["lib/to_worksheet.rb"].each {|file| require file }
4
+
5
+ class ToWorksheet
6
+ def self.return_array
7
+ [['apple', 1], ['orange', 0.5], ['pineapple', 2], ['watermelon', 3]]
8
+ end
9
+ end
10
+
11
+
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ToWorksheet do
4
+
5
+ it 'generate worksheet' do
6
+ worksheet = ToWorksheet.return_array.to_worksheet(:header => ['fruit', 'price'], :name => 'Price List')
7
+ file = File.new("/tmp/worksheet.xls", "w")
8
+ file.puts worksheet
9
+ file.close
10
+ end
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_worksheet
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Fabr\xC3\xADcio Ferrari de Campos"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-12 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Only to excel for now.
38
+ email: fabricio@vizir.com.br
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - lib/to_worksheet.rb
47
+ - spec/spec_helper.rb
48
+ - spec/to_worksheet/to_worksheet_spec.rb
49
+ - Rakefile
50
+ - .gemtest
51
+ has_rdoc: true
52
+ homepage: http://github.com/fabricioffc/to_worksheet
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 19
75
+ segments:
76
+ - 1
77
+ - 3
78
+ - 4
79
+ version: 1.3.4
80
+ requirements: []
81
+
82
+ rubyforge_project: to_worksheet
83
+ rubygems_version: 1.5.3
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Array conversion to a worksheet
87
+ test_files: []
88
+