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.
- data/.gitattributes +1 -1
- data/.gitignore +24 -24
- data/README.rdoc +34 -55
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -316
- data/charts/demo1.rb +46 -46
- data/charts/demo2.rb +65 -65
- data/charts/demo3.rb +117 -117
- data/charts/demo4.rb +119 -119
- data/charts/demo5.rb +48 -48
- data/examples/a_simple.rb +43 -43
- data/examples/autofilter.rb +265 -265
- data/examples/bigfile.rb +30 -30
- data/examples/chart_area.rb +121 -121
- data/examples/chart_bar.rb +120 -120
- data/examples/chart_column.rb +120 -120
- data/examples/chart_line.rb +120 -120
- data/examples/chart_pie.rb +108 -108
- data/examples/chart_scatter.rb +121 -121
- data/examples/chart_stock.rb +148 -148
- data/examples/chess.rb +142 -142
- data/examples/colors.rb +129 -129
- data/examples/comments1.rb +27 -27
- data/examples/comments2.rb +352 -352
- data/examples/copyformat.rb +52 -52
- data/examples/data_validate.rb +279 -279
- data/examples/date_time.rb +87 -87
- data/examples/defined_name.rb +32 -32
- data/examples/demo.rb +124 -124
- data/examples/diag_border.rb +36 -36
- data/examples/formats.rb +490 -490
- data/examples/formula_result.rb +30 -30
- data/examples/header.rb +137 -137
- data/examples/hide_sheet.rb +29 -29
- data/examples/hyperlink.rb +43 -43
- data/examples/images.rb +63 -63
- data/examples/indent.rb +31 -31
- data/examples/merge1.rb +40 -40
- data/examples/merge2.rb +45 -45
- data/examples/merge3.rb +66 -66
- data/examples/merge4.rb +83 -83
- data/examples/merge5.rb +80 -80
- data/examples/merge6.rb +67 -67
- data/examples/outline.rb +255 -255
- data/examples/outline_collapsed.rb +209 -209
- data/examples/panes.rb +113 -113
- data/examples/properties.rb +34 -34
- data/examples/properties_jp.rb +33 -33
- data/examples/protection.rb +47 -47
- data/examples/regions.rb +53 -53
- data/examples/repeat.rb +43 -43
- data/examples/right_to_left.rb +27 -27
- data/examples/row_wrap.rb +53 -53
- data/examples/stats.rb +74 -74
- data/examples/stocks.rb +81 -81
- data/examples/tab_colors.rb +31 -31
- data/examples/utf8.rb +15 -15
- data/examples/write_arrays.rb +83 -83
- data/lib/writeexcel/biffwriter.rb +232 -232
- data/lib/writeexcel/caller_info.rb +12 -12
- data/lib/writeexcel/chart.rb +2190 -2177
- data/lib/writeexcel/charts/area.rb +154 -154
- data/lib/writeexcel/charts/bar.rb +177 -177
- data/lib/writeexcel/charts/column.rb +156 -156
- data/lib/writeexcel/charts/external.rb +66 -66
- data/lib/writeexcel/charts/line.rb +154 -154
- data/lib/writeexcel/charts/pie.rb +169 -169
- data/lib/writeexcel/charts/scatter.rb +192 -192
- data/lib/writeexcel/charts/stock.rb +213 -213
- data/lib/writeexcel/colors.rb +64 -64
- data/lib/writeexcel/compatibility.rb +0 -255
- data/lib/writeexcel/debug_info.rb +37 -33
- data/lib/writeexcel/excelformulaparser.rb +587 -587
- data/lib/writeexcel/format.rb +13 -4
- data/lib/writeexcel/formula.rb +26 -9
- data/lib/writeexcel/helper.rb +68 -64
- data/lib/writeexcel/olewriter.rb +311 -311
- data/lib/writeexcel/properties.rb +242 -240
- data/lib/writeexcel/storage_lite.rb +984 -978
- data/lib/writeexcel/workbook.rb +3210 -3192
- data/lib/writeexcel/worksheet.rb +143 -51
- data/lib/writeexcel/write_file.rb +44 -40
- data/lib/writeexcel.rb +1159 -1159
- data/test/helper.rb +31 -28
- data/test/perl_output/README +31 -31
- data/test/test_00_IEEE_double.rb +13 -13
- data/test/test_01_add_worksheet.rb +10 -10
- data/test/test_02_merge_formats.rb +53 -53
- data/test/test_04_dimensions.rb +392 -392
- data/test/test_05_rows.rb +179 -179
- data/test/test_06_extsst.rb +77 -77
- data/test/test_11_date_time.rb +479 -479
- data/test/test_12_date_only.rb +501 -501
- data/test/test_13_date_seconds.rb +481 -481
- data/test/test_21_escher.rb +637 -637
- data/test/test_22_mso_drawing_group.rb +745 -745
- data/test/test_23_note.rb +73 -73
- data/test/test_24_txo.rb +75 -75
- data/test/test_25_position_object.rb +84 -84
- data/test/test_26_autofilter.rb +314 -314
- data/test/test_27_autofilter.rb +131 -131
- data/test/test_28_autofilter.rb +161 -161
- data/test/test_29_process_jpg.rb +683 -683
- data/test/test_30_validation_dval.rb +77 -77
- data/test/test_31_validation_dv_strings.rb +126 -126
- data/test/test_32_validation_dv_formula.rb +206 -206
- data/test/test_40_property_types.rb +188 -188
- data/test/test_41_properties.rb +235 -235
- data/test/test_42_set_properties.rb +437 -437
- data/test/test_50_name_stored.rb +299 -299
- data/test/test_51_name_print_area.rb +357 -357
- data/test/test_52_name_print_titles.rb +454 -454
- data/test/test_53_autofilter.rb +203 -203
- data/test/test_60_chart_generic.rb +578 -578
- data/test/test_61_chart_subclasses.rb +95 -95
- data/test/test_62_chart_formats.rb +272 -272
- data/test/test_63_chart_area_formats.rb +649 -649
- data/test/test_biff.rb +75 -75
- data/test/test_compatibility.rb +12 -627
- data/test/test_example_match.rb +3144 -3144
- data/test/test_formula.rb +61 -61
- data/test/test_ole.rb +106 -106
- data/test/test_storage_lite.rb +125 -125
- data/test/test_workbook.rb +139 -139
- data/test/test_worksheet.rb +110 -110
- data/utils/add_magic_comment.rb +80 -80
- data/writeexcel.gemspec +4 -6
- data/writeexcel.rdoc +58 -15
- metadata +9 -6
- data/test/test_new_encoding.rb +0 -205
data/lib/writeexcel/format.rb
CHANGED
@@ -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
|
-
|
376
|
-
rgch
|
377
|
-
|
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
|
data/lib/writeexcel/formula.rb
CHANGED
@@ -18,7 +18,8 @@ module Writeexcel
|
|
18
18
|
|
19
19
|
class Formula < ExcelFormulaParser #:nodoc:
|
20
20
|
require 'writeexcel/helper'
|
21
|
-
|
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
|
-
|
316
|
-
str
|
317
|
-
|
318
|
-
|
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
|
-
|
507
|
-
sheet_name
|
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?
|
data/lib/writeexcel/helper.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
private :utf8_to_16be
|
31
|
-
|
32
|
-
def utf8_to_16le(utf8)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|