writeexcel 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitattributes +1 -1
  2. data/.gitignore +24 -24
  3. data/README.rdoc +34 -55
  4. data/VERSION +1 -1
  5. data/charts/chartex.rb +316 -316
  6. data/charts/demo1.rb +46 -46
  7. data/charts/demo2.rb +65 -65
  8. data/charts/demo3.rb +117 -117
  9. data/charts/demo4.rb +119 -119
  10. data/charts/demo5.rb +48 -48
  11. data/examples/a_simple.rb +43 -43
  12. data/examples/autofilter.rb +265 -265
  13. data/examples/bigfile.rb +30 -30
  14. data/examples/chart_area.rb +121 -121
  15. data/examples/chart_bar.rb +120 -120
  16. data/examples/chart_column.rb +120 -120
  17. data/examples/chart_line.rb +120 -120
  18. data/examples/chart_pie.rb +108 -108
  19. data/examples/chart_scatter.rb +121 -121
  20. data/examples/chart_stock.rb +148 -148
  21. data/examples/chess.rb +142 -142
  22. data/examples/colors.rb +129 -129
  23. data/examples/comments1.rb +27 -27
  24. data/examples/comments2.rb +352 -352
  25. data/examples/copyformat.rb +52 -52
  26. data/examples/data_validate.rb +279 -279
  27. data/examples/date_time.rb +87 -87
  28. data/examples/defined_name.rb +32 -32
  29. data/examples/demo.rb +124 -124
  30. data/examples/diag_border.rb +36 -36
  31. data/examples/formats.rb +490 -490
  32. data/examples/formula_result.rb +30 -30
  33. data/examples/header.rb +137 -137
  34. data/examples/hide_sheet.rb +29 -29
  35. data/examples/hyperlink.rb +43 -43
  36. data/examples/images.rb +63 -63
  37. data/examples/indent.rb +31 -31
  38. data/examples/merge1.rb +40 -40
  39. data/examples/merge2.rb +45 -45
  40. data/examples/merge3.rb +66 -66
  41. data/examples/merge4.rb +83 -83
  42. data/examples/merge5.rb +80 -80
  43. data/examples/merge6.rb +67 -67
  44. data/examples/outline.rb +255 -255
  45. data/examples/outline_collapsed.rb +209 -209
  46. data/examples/panes.rb +113 -113
  47. data/examples/properties.rb +34 -34
  48. data/examples/properties_jp.rb +33 -33
  49. data/examples/protection.rb +47 -47
  50. data/examples/regions.rb +53 -53
  51. data/examples/repeat.rb +43 -43
  52. data/examples/right_to_left.rb +27 -27
  53. data/examples/row_wrap.rb +53 -53
  54. data/examples/stats.rb +74 -74
  55. data/examples/stocks.rb +81 -81
  56. data/examples/tab_colors.rb +31 -31
  57. data/examples/utf8.rb +15 -15
  58. data/examples/write_arrays.rb +83 -83
  59. data/lib/writeexcel/biffwriter.rb +232 -232
  60. data/lib/writeexcel/caller_info.rb +12 -12
  61. data/lib/writeexcel/chart.rb +2190 -2177
  62. data/lib/writeexcel/charts/area.rb +154 -154
  63. data/lib/writeexcel/charts/bar.rb +177 -177
  64. data/lib/writeexcel/charts/column.rb +156 -156
  65. data/lib/writeexcel/charts/external.rb +66 -66
  66. data/lib/writeexcel/charts/line.rb +154 -154
  67. data/lib/writeexcel/charts/pie.rb +169 -169
  68. data/lib/writeexcel/charts/scatter.rb +192 -192
  69. data/lib/writeexcel/charts/stock.rb +213 -213
  70. data/lib/writeexcel/colors.rb +64 -64
  71. data/lib/writeexcel/compatibility.rb +0 -255
  72. data/lib/writeexcel/debug_info.rb +37 -33
  73. data/lib/writeexcel/excelformulaparser.rb +587 -587
  74. data/lib/writeexcel/format.rb +13 -4
  75. data/lib/writeexcel/formula.rb +26 -9
  76. data/lib/writeexcel/helper.rb +68 -64
  77. data/lib/writeexcel/olewriter.rb +311 -311
  78. data/lib/writeexcel/properties.rb +242 -240
  79. data/lib/writeexcel/storage_lite.rb +984 -978
  80. data/lib/writeexcel/workbook.rb +3210 -3192
  81. data/lib/writeexcel/worksheet.rb +143 -51
  82. data/lib/writeexcel/write_file.rb +44 -40
  83. data/lib/writeexcel.rb +1159 -1159
  84. data/test/helper.rb +31 -28
  85. data/test/perl_output/README +31 -31
  86. data/test/test_00_IEEE_double.rb +13 -13
  87. data/test/test_01_add_worksheet.rb +10 -10
  88. data/test/test_02_merge_formats.rb +53 -53
  89. data/test/test_04_dimensions.rb +392 -392
  90. data/test/test_05_rows.rb +179 -179
  91. data/test/test_06_extsst.rb +77 -77
  92. data/test/test_11_date_time.rb +479 -479
  93. data/test/test_12_date_only.rb +501 -501
  94. data/test/test_13_date_seconds.rb +481 -481
  95. data/test/test_21_escher.rb +637 -637
  96. data/test/test_22_mso_drawing_group.rb +745 -745
  97. data/test/test_23_note.rb +73 -73
  98. data/test/test_24_txo.rb +75 -75
  99. data/test/test_25_position_object.rb +84 -84
  100. data/test/test_26_autofilter.rb +314 -314
  101. data/test/test_27_autofilter.rb +131 -131
  102. data/test/test_28_autofilter.rb +161 -161
  103. data/test/test_29_process_jpg.rb +683 -683
  104. data/test/test_30_validation_dval.rb +77 -77
  105. data/test/test_31_validation_dv_strings.rb +126 -126
  106. data/test/test_32_validation_dv_formula.rb +206 -206
  107. data/test/test_40_property_types.rb +188 -188
  108. data/test/test_41_properties.rb +235 -235
  109. data/test/test_42_set_properties.rb +437 -437
  110. data/test/test_50_name_stored.rb +299 -299
  111. data/test/test_51_name_print_area.rb +357 -357
  112. data/test/test_52_name_print_titles.rb +454 -454
  113. data/test/test_53_autofilter.rb +203 -203
  114. data/test/test_60_chart_generic.rb +578 -578
  115. data/test/test_61_chart_subclasses.rb +95 -95
  116. data/test/test_62_chart_formats.rb +272 -272
  117. data/test/test_63_chart_area_formats.rb +649 -649
  118. data/test/test_biff.rb +75 -75
  119. data/test/test_compatibility.rb +12 -627
  120. data/test/test_example_match.rb +3144 -3144
  121. data/test/test_formula.rb +61 -61
  122. data/test/test_ole.rb +106 -106
  123. data/test/test_storage_lite.rb +125 -125
  124. data/test/test_workbook.rb +139 -139
  125. data/test/test_worksheet.rb +110 -110
  126. data/utils/add_magic_comment.rb +80 -80
  127. data/writeexcel.gemspec +4 -6
  128. data/writeexcel.rdoc +58 -15
  129. metadata +9 -6
  130. data/test/test_new_encoding.rb +0 -205
@@ -6,75 +6,6 @@
6
6
  # copied from prawn.
7
7
  # modified by Hideo NAKAMURA
8
8
  #
9
- unless defined?(Encoding)
10
- class Encoding # :nodoc:
11
- class ConverterNotFoundError < StandardError; end
12
- class UndefinedConversionError < StandardError; end
13
-
14
- def self.const_missing (name)
15
- @looked_for ||= {}
16
- if !@looked_for.has_key?(name)
17
- begin
18
- @looked_for[name] = find(name)
19
- rescue ArgumentError
20
- @looked_for[name] = nil
21
- end
22
- end
23
- @looked_for[name]
24
- end
25
-
26
- def self.find (name)
27
- result = try_name name
28
- result ||= try_name name.gsub(/-/, '_') if name =~ /-/
29
- raise ArgumentError, "unknown encoding name - #{name}" unless result
30
- result
31
- end
32
- def self.try_name (name)
33
- dname = name.to_s.downcase
34
- sel = SupportedEncodings.select{ |se| dname == se.name.downcase }
35
- return sel.first if 1 <= sel.size
36
- sel = SupportedEncodings.select{ |se| se.name.downcase =~ Regexp.new(dname) }
37
- return sel.first if 1 <= sel.size
38
- nil
39
- end
40
-
41
- attr_accessor :name, :value
42
- def initialize (name, value)
43
- @name = name
44
- @value = value
45
- end
46
-
47
- def == (other)
48
- if other.is_a? Encoding
49
- other.value == @value
50
- elsif other.is_a? Fixnum
51
- other == @value
52
- else
53
- other == @name
54
- end
55
- end
56
-
57
- SupportedEncodings = [
58
- Encoding.new('ASCII', 0),
59
- Encoding.new('US_ASCII', 0),
60
- Encoding.new('BINARY', 1),
61
- Encoding.new('ASCII_8BIT', 1),
62
- Encoding.new('UTF_8', 2),
63
- Encoding.new('EUCJP', 3),
64
- Encoding.new('SJIS', 4),
65
- Encoding.new('UTF_16LE', 5),
66
- Encoding.new('UTF_16BE', 6)
67
- ]
68
- # ASCII = 0
69
- # BINARY = 1
70
- # UTF_8 = 2
71
- # EUCJP = 3
72
- # SJIS = 4
73
- # UTF_16LE = 5
74
- # UTF_16BE = 6
75
- end
76
- end
77
-
78
9
  class String #:nodoc:
79
10
  def first_line
80
11
  self.each_line { |line| return line }
@@ -93,156 +24,6 @@ class String #:nodoc:
93
24
  end
94
25
  end
95
26
 
96
- unless "".respond_to?(:encode)
97
- @encoding = Encoding::UTF_8
98
-
99
- def encode(encoding) # :nodoc:
100
- require 'nkf'
101
- @encoding ||= Encoding::UTF_8
102
- if @encoding == Encoding::UTF_8
103
- # supported only $KCODE = 'u'. so @encoding.nil? means UTF_8.
104
- case encoding
105
- when /ASCII$/i
106
- if self.mbchar?('UTF8')
107
- raise Encoding::UndefinedConversionError
108
- else
109
- str = String.new(self)
110
- str.force_encoding(encoding)
111
- str
112
- end
113
- when /(BINARY|ASCII[-_]8BIT)/i
114
- if self.mbchar?('UTF8')
115
- raise Encoding::UndefinedConversionError
116
- else
117
- str = String.new(self)
118
- str.force_encoding(encoding)
119
- str
120
- end
121
- when /UTF_8/i
122
- raise Encoding::ConverterNotFoundError
123
- when /EUCJP/i, /SJIS/i
124
- enc = encoding =~ /EUCJP/i ? 'e' : 's'
125
- str = NKF.nkf("-#{enc} -m0 -W", self)
126
- str.force_encoding(encoding)
127
- str
128
- when /UTF_16LE/i, /UTF_16BE/i
129
- raise Encoding::ConverterNotFoundError
130
- else
131
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
132
- end
133
- elsif @encoding == Encoding::ASCII
134
- case encoding
135
- when /ASCII/i, /BINARY/i, /EUCJP/i, /SJIS/i
136
- str = String.new(self)
137
- str.force_encoding(encoding)
138
- str
139
- when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
140
- raise Encoding::ConverterNotFoundError
141
- else
142
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
143
- end
144
- elsif @encoding == Encoding::BINARY
145
- case encoding
146
- when /ASCII$/i, /EUCJP/i, /SJIS/i
147
- if self.ascii_only? || self.mbchar?('UTF8') || self.mbchar?('EUCJP') || self.mbchar?('SJIS')
148
- raise Encoding::UndefinedConversionError
149
- else
150
- str = String.new(self)
151
- str.force_encoding(encoding)
152
- str
153
- end
154
- when /(BINARY|ASCII[-_]8BIT)/i
155
- self
156
- when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
157
- raise Encoding::ConverterNotFoundError
158
- else
159
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
160
- end
161
- elsif @encoding == Encoding::EUCJP || @encoding == Encoding::SJIS
162
- type = @encoding == Encoding::EUCJP ? 'EUCJP' : 'SJIS'
163
- inenc = @encoding == Encoding::EUCJP ? 'e' : 's'
164
- case encoding
165
- when /ASCII$/i
166
- if self.mbchar?(type)
167
- raise Encoding::UndefinedConversionError
168
- else
169
- str = String.new(self)
170
- str.force_encoding(encoding)
171
- str
172
- end
173
- when /(BINARY|ASCII[-_]8BIT)/i
174
- if self.mbchar?(type)
175
- raise Encoding::UndefinedConversionError
176
- else
177
- str = String.new(self)
178
- str.force_encoding(encoding)
179
- str
180
- end
181
- when /UTF_8/i
182
- raise Encoding::ConverterNotFoundError
183
- when /EUCJP/i, /SJIS/i
184
- outenc = encoding =~ /EUCJP/i ? 'E' : 'S'
185
- str = NKF.nkf("-#{inenc} -#{outenc}", self)
186
- str.force_encoding(encoding)
187
- str
188
- when /UTF_16LE/i, /UTF_16BE/i
189
- raise Encoding::ConverterNotFoundError
190
- else
191
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
192
- end
193
- elsif @encoding == Encoding::UTF_16LE || @encoding == Encoding::UTF_16BE
194
- enc = @encoding == Encoding::UTF_16LE ? 'L' : 'B'
195
- utf8 = NKF.nkf("-w -m0 -W16#{enc}", self)
196
- case encoding
197
- when /ASCII$/i
198
- if utf8.mbchar?
199
- raise Encoding::UndefinedConversionError
200
- else
201
- str = String.new(self)
202
- str.force_encoding(encoding)
203
- str
204
- end
205
- when /(BINARY|ASCII[-_]8BIT)/i
206
- if utf8.mbchar?
207
- raise Encoding::UndefinedConversionError
208
- else
209
- str = String.new(self)
210
- str.force_encoding(encoding)
211
- str
212
- end
213
- when /UTF_8/i
214
- raise Encoding::ConverterNotFoundError
215
- when /EUCJP/i, /SJIS/i
216
- str = String.new(self)
217
- str.force_encoding(encoding)
218
- str
219
- when /UTF_16LE/i, /UTF_16BE/i
220
- raise Encoding::ConverterNotFoundError
221
- else
222
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
223
- end
224
- else
225
- end
226
- end
227
-
228
- def self_with_encoding(encoding)
229
- found = Encoding.find(encoding)
230
- if found
231
- @encoding = found
232
- else
233
- raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
234
- end
235
- self
236
- end
237
- private :self_with_encoding
238
- end
239
-
240
- unless "".respond_to?(:encoding)
241
- def encoding
242
- @encoding ||= Encoding::UTF_8
243
- end
244
- end
245
-
246
27
  unless "".respond_to?(:bytesize)
247
28
  def bytesize # :nodoc:
248
29
  self.length
@@ -255,47 +36,11 @@ class String #:nodoc:
255
36
  end
256
37
  end
257
38
 
258
- unless "".respond_to?(:force_encoding)
259
- def force_encoding(encoding)
260
- if encoding.respond_to?(:to_str)
261
- found = Encoding.find(encoding)
262
- @encoding = found if found
263
- else
264
- @encoding = encoding if encoding.is_a?(Encoding)
265
- end
266
- self
267
- end
268
- end
269
-
270
39
  unless "".respond_to?(:ascii_only?)
271
40
  def ascii_only?
272
41
  !!(self =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/)
273
42
  end
274
43
  end
275
-
276
- if RUBY_VERSION < "1.9"
277
- unless "".respond_to?(:mbchar?)
278
- PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]' # :nodoc:
279
- PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]' # :nodoc:
280
- PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' # :nodoc:
281
-
282
- RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n') # :nodoc:
283
- RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n') # :nodoc:
284
- RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n') # :nodoc:
285
-
286
- def mbchar?(type = nil)# :nodoc: idea copied from jcode.rb
287
- if (!type.nil? && type =~ /SJIS/i) || $KCODE == 'SJIS'
288
- self =~ RE_SJIS
289
- elsif (!type.nil? && type =~ /EUCJP/i) || $KCODE == 'EUC'
290
- self =~ RE_EUC
291
- elsif (!type.nil? && type =~ /UTF_8/i) || $KCODE == 'UTF8'
292
- self =~ RE_UTF8
293
- else
294
- nil
295
- end
296
- end
297
- end
298
- end
299
44
  end
300
45
 
301
46
  unless File.respond_to?(:binread)
@@ -1,33 +1,37 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'writeexcel/caller_info'
4
-
5
- if defined?($debug)
6
- class BIFFWriter
7
- include CallerInfo
8
-
9
- def append(*args)
10
- data = args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join
11
- print_caller_info(data, :method => 'append')
12
- super
13
- end
14
-
15
- def prepend(*args)
16
- data = args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join
17
- print_caller_info(data, :method => 'prepend')
18
- super
19
- end
20
-
21
- def print_caller_info(data, param = {})
22
- infos = caller_info
23
-
24
- print "#{param[:method]}\n" if param[:method]
25
- infos.each do |info|
26
- print "#{info[:file]}:#{info[:line]}"
27
- print " in #{info[:method]}" if info[:method]
28
- print "\n"
29
- end
30
- print data.unpack('C*').map! {|byte| sprintf("%02X", byte) }.join(' ') + "\n\n"
31
- end
32
- end
33
- end
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'writeexcel/caller_info'
4
+
5
+ if defined?($debug)
6
+ class BIFFWriter
7
+ include CallerInfo
8
+
9
+ def append(*args)
10
+ data =
11
+ ruby_18 { args.join } ||
12
+ ruby_19 { args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
13
+ print_caller_info(data, :method => 'append')
14
+ super
15
+ end
16
+
17
+ def prepend(*args)
18
+ data =
19
+ ruby_18 { args.join } ||
20
+ ruby_19 { args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
21
+ print_caller_info(data, :method => 'prepend')
22
+ super
23
+ end
24
+
25
+ def print_caller_info(data, param = {})
26
+ infos = caller_info
27
+
28
+ print "#{param[:method]}\n" if param[:method]
29
+ infos.each do |info|
30
+ print "#{info[:file]}:#{info[:line]}"
31
+ print " in #{info[:method]}" if info[:method]
32
+ print "\n"
33
+ end
34
+ print data.unpack('C*').map! {|byte| sprintf("%02X", byte) }.join(' ') + "\n\n"
35
+ end
36
+ end
37
+ end