lib/write_xlsx/worksheet.rb in write_xlsx-1.09.0 vs lib/write_xlsx/worksheet.rb in write_xlsx-1.09.1

- old
+ new

@@ -66,10 +66,11 @@ @set_cols = {} @set_rows = {} @zoom = 100 @zoom_scale_normal = true @right_to_left = false + @leading_zeros = false @autofilter_area = nil @filter_on = false @filter_range = [] @filter_cols = {} @@ -830,10 +831,18 @@ # def print_black_and_white @page_setup.black_white = true end + # + # Causes the write() method to treat integers with a leading zero as a string. + # This ensures that any leading zeros such, as in zip codes, are maintained. + # + def keep_leading_zeros(flag = true) + @leading_zeros = !!flag + end + # # Display the worksheet right to left for some eastern versions of Excel. # def right_to_left(flag = true) @right_to_left = !!flag @@ -888,9 +897,12 @@ # Match an array ref. if token.respond_to?(:to_ary) write_row(*args) elsif token.respond_to?(:coerce) # Numeric write_number(*args) + # Match integer with leading zero(s) + elsif @leading_zeros && token =~ /^0\d*$/ + write_string(*args) elsif token =~ /^\d+$/ write_number(*args) # Match formula elsif token =~ /^=/ write_formula(*args)