sp-excel-loader 0.3.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +661 -0
  4. data/README.md +8 -0
  5. data/lib/sp-excel-loader.rb +6 -0
  6. data/lib/sp/excel/loader.rb +61 -0
  7. data/lib/sp/excel/loader/jrxml/band.rb +80 -0
  8. data/lib/sp/excel/loader/jrxml/band_container.rb +229 -0
  9. data/lib/sp/excel/loader/jrxml/box.rb +75 -0
  10. data/lib/sp/excel/loader/jrxml/casper_checkbox.rb +97 -0
  11. data/lib/sp/excel/loader/jrxml/casper_combo.rb +86 -0
  12. data/lib/sp/excel/loader/jrxml/casper_date.rb +54 -0
  13. data/lib/sp/excel/loader/jrxml/casper_radio_button.rb +48 -0
  14. data/lib/sp/excel/loader/jrxml/casper_text_field.rb +157 -0
  15. data/lib/sp/excel/loader/jrxml/client_combo_text_field.rb +72 -0
  16. data/lib/sp/excel/loader/jrxml/excel_to_jrxml.rb +1183 -0
  17. data/lib/sp/excel/loader/jrxml/extensions.rb +330 -0
  18. data/lib/sp/excel/loader/jrxml/field.rb +65 -0
  19. data/lib/sp/excel/loader/jrxml/group.rb +71 -0
  20. data/lib/sp/excel/loader/jrxml/image.rb +63 -0
  21. data/lib/sp/excel/loader/jrxml/jasper.rb +228 -0
  22. data/lib/sp/excel/loader/jrxml/parameter.rb +73 -0
  23. data/lib/sp/excel/loader/jrxml/pen.rb +97 -0
  24. data/lib/sp/excel/loader/jrxml/property.rb +52 -0
  25. data/lib/sp/excel/loader/jrxml/property_expression.rb +52 -0
  26. data/lib/sp/excel/loader/jrxml/report_element.rb +92 -0
  27. data/lib/sp/excel/loader/jrxml/static_text.rb +59 -0
  28. data/lib/sp/excel/loader/jrxml/style.rb +99 -0
  29. data/lib/sp/excel/loader/jrxml/text_field.rb +83 -0
  30. data/lib/sp/excel/loader/jrxml/variable.rb +77 -0
  31. data/lib/sp/excel/loader/json_to_xlsx.rb +159 -0
  32. data/lib/sp/excel/loader/model_exporter.rb +249 -0
  33. data/lib/sp/excel/loader/payrollexporter.rb +168 -0
  34. data/lib/sp/excel/loader/rubyxl_table_patch.rb +91 -0
  35. data/lib/sp/excel/loader/version.rb +26 -0
  36. data/lib/sp/excel/loader/workbookloader.rb +480 -0
  37. data/spec/calc_spec.rb +87 -0
  38. data/spec/model.xls +0 -0
  39. metadata +151 -0
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class Image < StaticText
27
+
28
+ attr_accessor :image_expression
29
+ attr_accessor :h_align
30
+ attr_accessor :v_align
31
+
32
+ def initialize
33
+ super()
34
+ @scale_image = 'RetainShape'
35
+ @h_align = 'Center'
36
+ @v_align = 'Middle'
37
+ @on_error_type = 'Blank'
38
+ @image_expression = ''
39
+ end
40
+
41
+ def attributes
42
+ { scaleImage: @scale_image, hAlign: @h_align, vAlign: @v_align, onErrorType: @on_error_type }
43
+ end
44
+
45
+ def to_xml (a_node)
46
+ Nokogiri::XML::Builder.with(a_node) do |xml|
47
+ xml.image(attributes)
48
+ end
49
+ @report_element.to_xml(a_node.children.last)
50
+ @box.to_xml(a_node.children.last) unless @box.nil?
51
+ Nokogiri::XML::Builder.with(a_node.children.last) do |xml|
52
+ xml.imageExpression {
53
+ xml.cdata(@image_expression)
54
+ }
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,228 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'set'
22
+
23
+ module Sp
24
+ module Excel
25
+ module Loader
26
+ module Jrxml
27
+
28
+ class JasperReport
29
+
30
+ #
31
+ # Attributes that can be configured using row tags
32
+ #
33
+ attr_accessor :column_width
34
+ attr_accessor :left_margin
35
+ attr_accessor :right_margin
36
+ attr_accessor :top_margin
37
+ attr_accessor :bottom_margin
38
+ attr_accessor :report_name
39
+ attr_accessor :is_title_new_page
40
+
41
+ #
42
+ # Report class instance data
43
+ #
44
+ attr_accessor :parameters
45
+ attr_accessor :styles
46
+ attr_accessor :style_set
47
+ attr_accessor :fields
48
+ attr_accessor :variables
49
+ attr_accessor :builder
50
+ attr_accessor :group
51
+ attr_accessor :query_string
52
+ attr_accessor :page_width
53
+ attr_accessor :page_height
54
+ attr_accessor :no_data_section
55
+ attr_accessor :orientation
56
+ attr_accessor :paper_size
57
+ attr_accessor :properties
58
+ attr_reader :extension
59
+
60
+ # band containers
61
+ attr_accessor :detail
62
+ attr_accessor :title
63
+ attr_accessor :background
64
+ attr_accessor :page_header
65
+ attr_accessor :column_header
66
+ attr_accessor :column_footer
67
+ attr_accessor :page_footer
68
+ attr_accessor :last_page_footer
69
+ attr_accessor :summary
70
+ attr_accessor :no_data
71
+
72
+ def initialize (a_name)
73
+
74
+ # init data set
75
+ @group = nil
76
+ @detail = nil
77
+ @title = nil
78
+ @background = nil
79
+ @page_header = nil
80
+ @column_header = nil
81
+ @column_footer = nil
82
+ @page_footer = nil
83
+ @last_page_footer = nil
84
+ @summary = nil
85
+ @no_data = nil
86
+
87
+ @query_string = 'lines'
88
+ @parameters = Hash.new
89
+ @fields = Hash.new
90
+ @variables = Hash.new
91
+ @styles = Hash.new
92
+ @style_set = Set.new
93
+
94
+ # defaults for jasper report attributes
95
+ @orientation = 'Portrait'
96
+ @paper_size = 'A4'
97
+ @page_width = 595
98
+ @page_height = 842
99
+ @no_data_section = 'NoPages'
100
+ @column_width = 522
101
+ @left_margin = 36
102
+ @right_margin = 37
103
+ @top_margin = 30
104
+ @bottom_margin = 30
105
+ @report_name = a_name
106
+ @is_title_new_page = false
107
+ @is_summary_with_page_header_and_footer = true;
108
+ @is_float_column_footer = true;
109
+ @generator_version = Sp::Excel::Loader::VERSION.strip
110
+ @fields['data_row_type'] = Field.new('data_row_type')
111
+ @variables['ON_LAST_PAGE'] = Variable.new('ON_LAST_PAGE', 'java.lang.Boolean')
112
+
113
+ @extension = ReportExtension.new(@report_name)
114
+
115
+ end
116
+
117
+ def update_page_size
118
+ case @paper_size
119
+ when 'A4'
120
+ if @orientation == 'Landscape'
121
+ @page_width = 842
122
+ @page_height = 595
123
+ else
124
+ @page_width = 595
125
+ @page_height = 842
126
+ end
127
+ else
128
+ @page_width = 595
129
+ @page_height = 842
130
+ end
131
+ end
132
+
133
+ def update_extension_style (a_name, a_cell)
134
+ @extension.styles.delete_if {|style| style.name == a_name}
135
+ style = @styles.delete("style_#{a_cell.style_index+1}")
136
+ style.name = a_name
137
+ style.v_text_align = nil
138
+ style.h_text_align = nil
139
+ @styles[a_name] = style
140
+ @style_set.add(a_name)
141
+ end
142
+
143
+ def to_xml
144
+ @builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
145
+ xml.jasperReport('xmlns' => 'http://jasperreports.sourceforge.net/jasperreports',
146
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
147
+ 'xsi:schemaLocation' => 'http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd',
148
+ 'name' => @report_name,
149
+ 'pageWidth' => @page_width,
150
+ 'pageHeight' => @page_height,
151
+ 'whenNoDataType' => @no_data_section,
152
+ 'columnWidth' => @column_width,
153
+ 'leftMargin' => @left_margin,
154
+ 'rightMargin' => @right_margin,
155
+ 'topMargin' => @top_margin,
156
+ 'bottomMargin' => @bottom_margin,
157
+ 'isTitleNewPage' => @is_title_new_page,
158
+ 'isSummaryWithPageHeaderAndFooter' => @is_summary_with_page_header_and_footer,
159
+ 'isFloatColumnFooter' => @is_float_column_footer) {
160
+ xml.comment('created with sp-excel-loader ' + @generator_version)
161
+ }
162
+ end
163
+
164
+ if not @extension.nil?
165
+
166
+ if not @extension.properties.nil?
167
+ @extension.properties.each do |property|
168
+ property.to_xml(@builder.doc.children[0])
169
+ end
170
+ end
171
+
172
+ if not @extension.styles.nil?
173
+ @extension.styles.each do |style|
174
+ style.to_xml(@builder.doc.children[0])
175
+ end
176
+ end
177
+ end
178
+
179
+ @styles.each do |name, style|
180
+ if @style_set.include? name
181
+ style.to_xml(@builder.doc.children[0])
182
+ end
183
+ end
184
+
185
+ @parameters.each do |name, parameter|
186
+ parameter.to_xml(@builder.doc.children[0])
187
+ end
188
+
189
+ unless @query_string.nil?
190
+ Nokogiri::XML::Builder.with(@builder.doc.children[0]) do |xml|
191
+ xml.queryString {
192
+ xml.cdata(@query_string)
193
+ }
194
+ end
195
+ end
196
+
197
+ @fields.each do |name, field|
198
+ field.to_xml(@builder.doc.children[0])
199
+ end
200
+
201
+ @variables.each do |name, variable|
202
+ next if ['PAGE_NUMBER', 'MASTER_CURRENT_PAGE', 'MASTER_TOTAL_PAGES',
203
+ 'COLUMN_NUMBER', 'REPORT_COUNT', 'PAGE_COUNT', 'COLUMN_COUNT'].include? name
204
+ variable.to_xml(@builder.doc.children[0])
205
+ end
206
+
207
+ @group.to_xml(@builder.doc.children[0]) unless @group.nil?
208
+
209
+ @background.to_xml(@builder.doc.children[0]) unless @background.nil?
210
+ @title.to_xml(@builder.doc.children[0]) unless @title.nil?
211
+ @page_header.to_xml(@builder.doc.children[0]) unless @page_header.nil?
212
+ @column_header.to_xml(@builder.doc.children[0]) unless @column_header.nil?
213
+ @detail.to_xml(@builder.doc.children[0]) unless @detail.nil?
214
+ @column_footer.to_xml(@builder.doc.children[0]) unless @column_footer.nil?
215
+ @page_footer.to_xml(@builder.doc.children[0]) unless @page_footer.nil?
216
+ @last_page_footer.to_xml(@builder.doc.children[0]) unless @last_page_footer.nil?
217
+ @summary.to_xml(@builder.doc.children[0]) unless @summary.nil?
218
+ @no_data.to_xml(@builder.doc.children[0]) unless @no_data.nil?
219
+
220
+ @builder.to_xml(indent:2)
221
+ end
222
+
223
+ end
224
+
225
+ end
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class Parameter
27
+
28
+ attr_accessor :name
29
+ attr_accessor :java_class
30
+ attr_accessor :description
31
+ attr_accessor :default_value_expression
32
+ attr_accessor :is_for_prompting
33
+
34
+ def initialize (a_name, a_java_class = nil)
35
+ @name = a_name
36
+ @java_class = a_java_class
37
+ @java_class ||= 'java.lang.String'
38
+ @description = nil
39
+ @default_value_expression = nil
40
+ @is_for_prompting = false
41
+ end
42
+
43
+ def attributes
44
+ rv = Hash.new
45
+ rv['name'] = @name
46
+ rv['class'] = @java_class
47
+ rv['isForPrompting'] = false if @is_for_prompting == false
48
+ return rv
49
+ end
50
+
51
+ def to_xml (a_node)
52
+ Nokogiri::XML::Builder.with(a_node) do |xml|
53
+ xml.parameter(attributes) {
54
+ unless @description.nil?
55
+ xml.parameterDescription {
56
+ xml.cdata @description
57
+ }
58
+ end
59
+ unless @default_value_expression.nil?
60
+ xml.defaultValueExpression {
61
+ xml.cdata @default_value_expression
62
+ }
63
+ end
64
+ }
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class Pen
27
+
28
+ attr_accessor :line_width
29
+ attr_accessor :line_style
30
+ attr_accessor :line_color
31
+
32
+ def initialize
33
+ @line_width = 1.0
34
+ @line_style = 'Solid'
35
+ @line_color = '#000000'
36
+ end
37
+
38
+ def attributes
39
+ rv = Hash.new
40
+ rv['lineWidth'] = @line_width unless @line_width.nil?
41
+ rv['lineStyle'] = @line_style unless @line_style.nil?
42
+ rv['lineColor'] = @line_color unless @line_color.nil?
43
+ return rv
44
+ end
45
+
46
+ def to_xml (a_node)
47
+ Nokogiri::XML::Builder.with(a_node) do |xml|
48
+ xml.pen(attributes)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ class TopPen < Pen
55
+
56
+ def to_xml (a_node)
57
+ Nokogiri::XML::Builder.with(a_node) do |xml|
58
+ xml.topPen(attributes)
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ class LeftPen < Pen
65
+
66
+ def to_xml (a_node)
67
+ Nokogiri::XML::Builder.with(a_node) do |xml|
68
+ xml.leftPen(attributes)
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ class RightPen < Pen
75
+
76
+ def to_xml (a_node)
77
+ Nokogiri::XML::Builder.with(a_node) do |xml|
78
+ xml.rightPen(attributes)
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ class BottomPen < Pen
85
+
86
+ def to_xml (a_node)
87
+ Nokogiri::XML::Builder.with(a_node) do |xml|
88
+ xml.bottomPen(attributes)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end