lib/write_xlsx/worksheet.rb in write_xlsx-0.79.0 vs lib/write_xlsx/worksheet.rb in write_xlsx-0.80.0

- old
+ new

@@ -1487,11 +1487,11 @@ row_max += 1 area = "$#{row_min}:$#{row_max}" # Build up the print titles "Sheet1!$1:$2" - sheetname = quote_sheetname(name) + sheetname = quote_sheetname(@name) @page_setup.repeat_rows = "#{sheetname}!#{area}" end def print_repeat_rows # :nodoc: @page_setup.repeat_rows @@ -7513,20 +7513,27 @@ else area = "#{range1}:#{range2}" end # Build up the print area range "Sheet1!$A$1:$C$13". - "#{quote_sheetname(name)}!#{area}" + "#{quote_sheetname(@name)}!#{area}" end # # Sheetnames used in references should be quoted if they contain any spaces, # special characters or if the look like something that isn't a sheet name. # TODO. We need to handle more special cases. # def quote_sheetname(sheetname) #:nodoc: - return sheetname if sheetname =~ /^Sheet\d+$/ - return "'#{sheetname}'" + # Use Excel's conventions and quote the sheet name if it comtains any + # non-word character or if it isn't already quoted. + name = sheetname.dup + if name =~ /\W/ && !(name =~ /^'/) + # Double quote and single quoted strings. + name = name.gsub(/'/, "''") + name = "'#{name}'" + end + name end def fit_page? #:nodoc: @page_setup.fit_page end