excel_to_code 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- require 'nokogiri'
2
-
3
- class ExtractValues < Nokogiri::XML::SAX::Document
4
-
5
- def self.extract(*args)
6
- self.new.extract(*args)
7
- end
8
-
9
- def extract(sheet_name, input)
10
- @sheet_name = sheet_name.to_sym
11
- @output = {}
12
- @parsing = false
13
- @fp = CachingFormulaParser.instance
14
- Nokogiri::XML::SAX::Parser.new(self).parse(input)
15
- @output
16
- end
17
-
18
- attr_accessor :ref, :type, :value
19
-
20
- def start_element(name,attributes)
21
- if name == "v"
22
- @parsing = true
23
- @value = []
24
- elsif name == "c"
25
- @ref = attributes.assoc('r').last.to_sym
26
- type = attributes.assoc('t')
27
- @type = type ? type.last : "n"
28
- end
29
- end
30
-
31
- def end_element(name)
32
- return unless name == "v"
33
- @parsing = false
34
- value = @value.join
35
- ast = case @type
36
- when 'b'; value == "1" ? [:boolean_true] : [:boolean_false]
37
- when 's'; [:shared_string,value.to_i]
38
- when 'n'; [:number,value.to_f]
39
- when 'e'; [:error,value.to_sym]
40
- when 'str'; [:string,value.gsub(/_x[0-9A-F]{4}_/,'').freeze]
41
- else
42
- $stderr.puts "Type #{type} not known #{@sheet_name} #{@ref}"
43
- exit
44
- end
45
- @output[[@sheet_name, @ref]] = @fp.map(ast)
46
- end
47
-
48
- def characters(string)
49
- return unless @parsing
50
- @value << string
51
- end
52
-
53
- end
@@ -1,21 +0,0 @@
1
- require 'nokogiri'
2
-
3
- class ExtractWorksheetDimensions < Nokogiri::XML::SAX::Document
4
-
5
- def self.extract(*args)
6
- self.new.extract(*args)
7
- end
8
-
9
- def extract(input)
10
- parser = Nokogiri::XML::SAX::Parser.new(self)
11
- parser.parse(input)
12
- @output
13
- end
14
-
15
- # FIXME: Is there an elegant way to abort once we have found the dimension tag?
16
- def start_element(name,attributes)
17
- return false unless name == "dimension"
18
- @output = attributes.assoc('ref').last
19
- end
20
-
21
- end
@@ -1,22 +0,0 @@
1
- require 'nokogiri'
2
-
3
-
4
- class ExtractWorksheetTableRelationships < Nokogiri::XML::SAX::Document
5
-
6
- def self.extract(*args)
7
- self.new.extract(*args)
8
- end
9
-
10
- def extract(input)
11
- @output = []
12
- @parsing = false
13
- Nokogiri::XML::SAX::Parser.new(self).parse(input)
14
- @output
15
- end
16
-
17
- def start_element(name,attributes)
18
- return false unless name == "tablePart"
19
- @output << "#{attributes.assoc('r:id').last}"
20
- end
21
-
22
- end
@@ -1,17 +0,0 @@
1
- require 'nokogiri'
2
-
3
- class SimpleExtractFromXML < Nokogiri::XML::SAX::Document
4
-
5
- def self.extract(*args)
6
- self.new.extract(*args)
7
- end
8
-
9
- def extract(sheet_name, input)
10
- @sheet_name = sheet_name
11
- @output = {}
12
- @parsing = false
13
- Nokogiri::XML::SAX::Parser.new(self).parse(input)
14
- @output
15
- end
16
-
17
- end