writeexcel 0.5.0 → 0.6.0

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.
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
@@ -23,6 +23,7 @@ require 'writeexcel/colors'
23
23
  module Writeexcel
24
24
 
25
25
  class Format < Colors
26
+ NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/
26
27
 
27
28
  ###############################################################################
28
29
  #
@@ -369,12 +370,20 @@ class Format < Colors
369
370
  rgch = @font
370
371
  encoding = @font_encoding
371
372
 
372
- rgch = convert_to_ascii_if_ascii(rgch)
373
+ ruby_19 { rgch = convert_to_ascii_if_ascii(rgch) }
373
374
 
374
375
  # Handle utf8 strings
375
- if rgch.encoding == Encoding::UTF_8
376
- rgch = utf8_to_16be(rgch)
377
- encoding = 1
376
+ ruby_18 do
377
+ if rgch =~ NonAscii
378
+ rgch = utf8_to_16be(rgch)
379
+ encoding = 1
380
+ end
381
+ end
382
+ ruby_19 do
383
+ if rgch.encoding == Encoding::UTF_8
384
+ rgch = utf8_to_16be(rgch)
385
+ encoding = 1
386
+ end
378
387
  end
379
388
 
380
389
  cch = rgch.bytesize
@@ -18,7 +18,8 @@ module Writeexcel
18
18
 
19
19
  class Formula < ExcelFormulaParser #:nodoc:
20
20
  require 'writeexcel/helper'
21
- private :convert_to_ascii_if_ascii
21
+
22
+ NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/
22
23
 
23
24
  attr_accessor :byte_order, :workbook, :ext_sheets, :ext_refs, :ext_ref_count
24
25
 
@@ -299,7 +300,7 @@ class Formula < ExcelFormulaParser #:nodoc:
299
300
  # Convert a string to a ptg Str.
300
301
  #
301
302
  def convert_string(str)
302
- str = convert_to_ascii_if_ascii(str)
303
+ ruby_19 { str = convert_to_ascii_if_ascii(str) }
303
304
 
304
305
  encoding = 0
305
306
 
@@ -312,10 +313,19 @@ class Formula < ExcelFormulaParser #:nodoc:
312
313
  ruby_19 { str.length }
313
314
 
314
315
  # Handle utf8 strings
315
- if str.encoding == Encoding::UTF_8
316
- str = utf8_to_16le(str)
317
- str.force_encoding('BINARY')
318
- encoding = 1
316
+ ruby_18 do
317
+ if str =~ NonAscii
318
+ str = utf8_to_16le(str)
319
+ ruby_19 { str.force_encoding('BINARY') }
320
+ encoding = 1
321
+ end
322
+ end
323
+ ruby_19 do
324
+ if str.encoding == Encoding::UTF_8
325
+ str = utf8_to_16le(str)
326
+ ruby_19 { str.force_encoding('BINARY') }
327
+ encoding = 1
328
+ end
319
329
  end
320
330
 
321
331
  exit "String in formula has more than 255 chars\n" if length > 255
@@ -500,11 +510,18 @@ class Formula < ExcelFormulaParser #:nodoc:
500
510
  # sheet names is updated by the add_worksheet() method of the Workbook class.
501
511
  #
502
512
  def get_sheet_index(sheet_name)
503
- sheet_name = convert_to_ascii_if_ascii(sheet_name)
513
+ ruby_19 { sheet_name = convert_to_ascii_if_ascii(sheet_name) }
504
514
 
505
515
  # Handle utf8 sheetnames
506
- if sheet_name.encoding == Encoding::UTF_8
507
- sheet_name = sheet_name.encode('UTF-16BE')
516
+ ruby_18 do
517
+ if sheet_name =~ NonAscii
518
+ sheet_name = utf8_to_16be(sheet_name)
519
+ end
520
+ end
521
+ ruby_19 do
522
+ if sheet_name.encoding == Encoding::UTF_8
523
+ sheet_name = sheet_name.encode('UTF-16BE')
524
+ end
508
525
  end
509
526
 
510
527
  if @ext_sheets[sheet_name].nil?
@@ -1,64 +1,68 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # helper.rb
4
- #
5
- # Convert to US_ASCII encoding if ascii characters only.
6
- def convert_to_ascii_if_ascii(str)
7
- return nil if str.nil?
8
- ruby_18 do
9
- enc = str.encoding
10
- begin
11
- str = str.encode('ASCII')
12
- rescue
13
- str.force_encoding(enc)
14
- end
15
- end ||
16
- ruby_19 do
17
- if !str.nil? && str.ascii_only?
18
- str = [str].pack('a*')
19
- end
20
- end
21
- str
22
- end
23
- private :convert_to_ascii_if_ascii
24
-
25
-
26
- def utf8_to_16be(utf8)
27
- utf16be = NKF.nkf('-w16B0 -m0 -W', utf8)
28
- utf16be.force_encoding('UTF-16BE')
29
- end
30
- private :utf8_to_16be
31
-
32
- def utf8_to_16le(utf8)
33
- utf16le = NKF.nkf('-w16L0 -m0 -W', utf8)
34
- utf16le.force_encoding('UTF-16LE')
35
- end
36
- private :utf8_to_16le
37
-
38
- def ascii_to_16be(ascii)
39
- ascii.unpack("C*").pack("n*")
40
- ascii.force_encoding('UTF-16BE')
41
- end
42
- private :ascii_to_16be
43
-
44
- def store_simple(record, length, *args)
45
- header = [record, length].pack('vv')
46
- data = args.collect { |arg| [arg].pack('v') }.join('')
47
-
48
- append(header, data)
49
- end
50
- private :store_simple
51
-
52
- # Convert base26 column string to a number.
53
- # All your Base are belong to us.
54
- def chars_to_col(chars)
55
- expn = 0
56
- col = 0
57
- while (!chars.empty?)
58
- char = chars.pop # LS char first
59
- col += (char.ord - "A".ord + 1) * (26 ** expn)
60
- expn += 1
61
- end
62
- col
63
- end
64
- private :chars_to_col
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # helper.rb
4
+ #
5
+ # Convert to US_ASCII encoding if ascii characters only.
6
+ def convert_to_ascii_if_ascii(str)
7
+ return nil if str.nil?
8
+ ruby_18 do
9
+ unless str =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/
10
+ str = String.new(str)
11
+ end
12
+ end ||
13
+ ruby_19 do
14
+ if str.ascii_only?
15
+ str = [str].pack('a*')
16
+ end
17
+ end
18
+ str
19
+ end
20
+ private :convert_to_ascii_if_ascii
21
+
22
+
23
+ def utf8_to_16be(utf8)
24
+ ruby_18 { NKF.nkf('-w16B0 -m0 -W', utf8) } ||
25
+ ruby_19 do
26
+ utf16be = NKF.nkf('-w16B0 -m0 -W', utf8)
27
+ utf16be.force_encoding('UTF-16BE')
28
+ end
29
+ end
30
+ private :utf8_to_16be
31
+
32
+ def utf8_to_16le(utf8)
33
+ ruby_18 { NKF.nkf('-w16L0 -m0 -W', utf8) } ||
34
+ ruby_19 do
35
+ utf16le = NKF.nkf('-w16L0 -m0 -W', utf8)
36
+ utf16le.force_encoding('UTF-16LE')
37
+ end
38
+ end
39
+ private :utf8_to_16le
40
+
41
+ def ascii_to_16be(ascii)
42
+ ascii.unpack("C*").pack("n*")
43
+ ruby_19 { ascii.force_encoding('UTF-16BE') }
44
+ ascii
45
+ end
46
+ private :ascii_to_16be
47
+
48
+ def store_simple(record, length, *args)
49
+ header = [record, length].pack('vv')
50
+ data = args.collect { |arg| [arg].pack('v') }.join('')
51
+
52
+ append(header, data)
53
+ end
54
+ private :store_simple
55
+
56
+ # Convert base26 column string to a number.
57
+ # All your Base are belong to us.
58
+ def chars_to_col(chars)
59
+ expn = 0
60
+ col = 0
61
+ while (!chars.empty?)
62
+ char = chars.pop # LS char first
63
+ col += (char.ord - "A".ord + 1) * (26 ** expn)
64
+ expn += 1
65
+ end
66
+ col
67
+ end
68
+ private :chars_to_col