write_xlsx 1.09.0 → 1.09.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/examples/keep_leading_zeros.rb +17 -0
- data/keep_leading_zeros.xlsx +0 -0
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/worksheet.rb +12 -0
- data/test/perl_output/keep_leading_zeros.xlsx +0 -0
- data/test/test_example_match.rb +18 -0
- metadata +6 -3
- data/ignore_errors.xlsx +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc4fb820c659853dbdd8596b1f61f667641b69dbc5c404f81d19acf514f2d905
|
4
|
+
data.tar.gz: 7ff1ff5c651b23c8e9883e23421065e778e6c8ba109f23d46ff1886a33a6852b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9461389a984b4826addf2dc69c1760cc92b07d456118be8835a982601587eaec02628016e413b496c5a7db5fc59c4c246962afc286707b3371eab06e5c7fbe4a
|
7
|
+
data.tar.gz: a9bdd5e0191277a5097f2f2e0634a0c745a7223c81a1f6116769d8b2a93c5ab67aa10e61e19eb3860d7740f5f90bcf1045066c591f10bb62009d6b0916888df9
|
data/Changes
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
2
|
|
3
|
+
2021-11-27 v1.09.1
|
4
|
+
Added Worksheet#kee_leading_zeros method to handle '001' as string in
|
5
|
+
Worksheet#write, write_row, and write_col method.
|
6
|
+
|
3
7
|
2021-11-26 v1.09.0
|
4
8
|
|
5
9
|
Added support for background images in worksheets. See set_background().
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'write_xlsx'
|
5
|
+
|
6
|
+
workbook = WriteXLSX.new('keep_leading_zeros.xlsx')
|
7
|
+
worksheet = workbook.add_worksheet
|
8
|
+
|
9
|
+
worksheet.keep_leading_zeros(true)
|
10
|
+
worksheet.write('A1', '001')
|
11
|
+
worksheet.write('B1', 'written as string.')
|
12
|
+
worksheet.write('A2', '012')
|
13
|
+
worksheet.write('B2', 'written as string.')
|
14
|
+
worksheet.write('A3', '123')
|
15
|
+
worksheet.write('B3', 'written as number.')
|
16
|
+
|
17
|
+
workbook.close
|
Binary file
|
data/lib/write_xlsx/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
WriteXLSX_VERSION = "1.09.
|
1
|
+
WriteXLSX_VERSION = "1.09.1"
|
data/lib/write_xlsx/worksheet.rb
CHANGED
@@ -68,6 +68,7 @@ module Writexlsx
|
|
68
68
|
@zoom = 100
|
69
69
|
@zoom_scale_normal = true
|
70
70
|
@right_to_left = false
|
71
|
+
@leading_zeros = false
|
71
72
|
|
72
73
|
@autofilter_area = nil
|
73
74
|
@filter_on = false
|
@@ -832,6 +833,14 @@ module Writexlsx
|
|
832
833
|
@page_setup.black_white = true
|
833
834
|
end
|
834
835
|
|
836
|
+
#
|
837
|
+
# Causes the write() method to treat integers with a leading zero as a string.
|
838
|
+
# This ensures that any leading zeros such, as in zip codes, are maintained.
|
839
|
+
#
|
840
|
+
def keep_leading_zeros(flag = true)
|
841
|
+
@leading_zeros = !!flag
|
842
|
+
end
|
843
|
+
|
835
844
|
#
|
836
845
|
# Display the worksheet right to left for some eastern versions of Excel.
|
837
846
|
#
|
@@ -890,6 +899,9 @@ module Writexlsx
|
|
890
899
|
write_row(*args)
|
891
900
|
elsif token.respond_to?(:coerce) # Numeric
|
892
901
|
write_number(*args)
|
902
|
+
# Match integer with leading zero(s)
|
903
|
+
elsif @leading_zeros && token =~ /^0\d*$/
|
904
|
+
write_string(*args)
|
893
905
|
elsif token =~ /^\d+$/
|
894
906
|
write_number(*args)
|
895
907
|
# Match formula
|
Binary file
|
data/test/test_example_match.rb
CHANGED
@@ -3335,6 +3335,24 @@ EOS
|
|
3335
3335
|
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
3336
3336
|
end
|
3337
3337
|
|
3338
|
+
def test_keep_leading_zoros
|
3339
|
+
@xlsx = 'keep_leading_zeros.xlsx'
|
3340
|
+
workbook = WriteXLSX.new(@io)
|
3341
|
+
worksheet = workbook.add_worksheet
|
3342
|
+
|
3343
|
+
worksheet.keep_leading_zeros(true)
|
3344
|
+
worksheet.write('A1', '001')
|
3345
|
+
worksheet.write('B1', 'written as string.')
|
3346
|
+
worksheet.write('A2', '012')
|
3347
|
+
worksheet.write('B2', 'written as string.')
|
3348
|
+
worksheet.write('A3', '123')
|
3349
|
+
worksheet.write('B3', 'written as number.')
|
3350
|
+
|
3351
|
+
workbook.close
|
3352
|
+
store_to_tempfile
|
3353
|
+
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
3354
|
+
end
|
3355
|
+
|
3338
3356
|
def test_merge1
|
3339
3357
|
@xlsx = 'merge1.xlsx'
|
3340
3358
|
# Create a new workbook and add a worksheet
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: write_xlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.09.
|
4
|
+
version: 1.09.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hideo NAKAMURA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- examples/hyperlink1.rb
|
141
141
|
- examples/ignore_errors.rb
|
142
142
|
- examples/indent.rb
|
143
|
+
- examples/keep_leading_zeros.rb
|
143
144
|
- examples/macros.rb
|
144
145
|
- examples/merge1.rb
|
145
146
|
- examples/merge2.rb
|
@@ -174,7 +175,7 @@ files:
|
|
174
175
|
- examples/tables.rb
|
175
176
|
- examples/update_range_format_with_params.rb
|
176
177
|
- examples/vbaProject.bin
|
177
|
-
-
|
178
|
+
- keep_leading_zeros.xlsx
|
178
179
|
- lib/write_xlsx.rb
|
179
180
|
- lib/write_xlsx/chart.rb
|
180
181
|
- lib/write_xlsx/chart/area.rb
|
@@ -371,6 +372,7 @@ files:
|
|
371
372
|
- test/perl_output/hyperlink.xlsx
|
372
373
|
- test/perl_output/ignore_errors.xlsx
|
373
374
|
- test/perl_output/indent.xlsx
|
375
|
+
- test/perl_output/keep_leading_zeros.xlsx
|
374
376
|
- test/perl_output/merge1.xlsx
|
375
377
|
- test/perl_output/merge2.xlsx
|
376
378
|
- test/perl_output/merge3.xlsx
|
@@ -2329,6 +2331,7 @@ test_files:
|
|
2329
2331
|
- test/perl_output/hyperlink.xlsx
|
2330
2332
|
- test/perl_output/ignore_errors.xlsx
|
2331
2333
|
- test/perl_output/indent.xlsx
|
2334
|
+
- test/perl_output/keep_leading_zeros.xlsx
|
2332
2335
|
- test/perl_output/merge1.xlsx
|
2333
2336
|
- test/perl_output/merge2.xlsx
|
2334
2337
|
- test/perl_output/merge3.xlsx
|
data/ignore_errors.xlsx
DELETED
Binary file
|