lib/write_xlsx/workbook.rb in write_xlsx-1.07.0 vs lib/write_xlsx/workbook.rb in write_xlsx-1.08.0

- old
+ new

@@ -50,10 +50,11 @@ attr_reader :vba_project # :nodoc: attr_reader :excel2003_style # :nodoc: attr_reader :max_url_length # :nodoc: attr_reader :strings_to_urls # :nodoc: attr_reader :default_url_format # :nodoc: + attr_reader :read_only # :nodoc: # # A new Excel workbook is created using the +new+ constructor # which accepts either a filename or an IO object as a parameter. # The following example creates a new Excel file based on a filename: @@ -131,10 +132,11 @@ @images = [] @strings_to_urls = (options[:strings_to_urls].nil? || options[:strings_to_urls]) ? true : false @max_url_length = 2079 @has_comments = false + @read_only = 0 if options[:max_url_length] @max_url_length = options[:max_url_length] @max_url_length = 2079 if @max_url_length < 250 end @@ -290,10 +292,13 @@ write_workbook do # Write the XLSX file version. write_file_version + # Write the fileSharing element. + write_file_sharing + # Write the workbook properties. write_workbook_pr # Write the workbook view properties. write_book_views @@ -953,10 +958,17 @@ @vba_codename = 'ThisWorkbook' end end # + # Set the Excel "Read-only recommended" save option. + # + def read_only_recommended + @read_only = 2 + end + + # # set_calc_mode() # # Set the Excel caclcuation mode for the workbook. # def set_calc_mode(mode, calc_id = nil) @@ -1307,9 +1319,20 @@ if @vba_project attributes << [:codeName, '{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}'] end @writer.empty_tag('fileVersion', attributes) + end + + # + # Write the <fileSharing> element. + # + def write_file_sharing + return if !ptrue?(@read_only) + + attributes = [] + attributes << ['readOnlyRecommended', 1] + @writer.empty_tag('fileSharing', attributes) end def write_workbook_pr #:nodoc: attributes = [] attributes << ['codeName', @vba_codename] if ptrue?(@vba_codename)