lib/axlsx/workbook/workbook.rb in axlsx-1.0.15 vs lib/axlsx/workbook/workbook.rb in axlsx-1.0.16

- old
+ new

@@ -80,21 +80,31 @@ # w.parse_string :date1904, "//xmlns:workbookPr/@date1904" # w #end # Creates a new Workbook - # @option options [Boolean] date1904 + # + # @option options [Boolean] date1904. If this is not specified, we try to determine if the platform is bsd/darwin and set date1904 to true automatically. + # def initialize(options={}) @styles = Styles.new @worksheets = SimpleTypedList.new Worksheet @drawings = SimpleTypedList.new Drawing @charts = SimpleTypedList.new Chart @images = SimpleTypedList.new Pic - self.date1904= options[:date1904] unless options[:date1904].nil? + self.date1904= options[:date1904].nil? ? is_bsd? : options[:date1904] yield self if block_given? end + # Uses RUBY_PLATFORM constant to determine if the OS is freebsd or darwin + # based on this value we attempt to set date1904. + # @return [Boolean] + def is_bsd? + platform = RUBY_PLATFORM.downcase + platform.include?('freebsd') || platform.include?('darwin') + end + # Instance level access to the class variable 1904 # @return [Boolean] def date1904() @@date1904; end # see @date1904 @@ -142,20 +152,20 @@ # Serializes the workbook document # @return [String] def to_xml() add_worksheet unless worksheets.size > 0 - builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| + builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| xml.workbook(:xmlns => XML_NS, :'xmlns:r' => XML_NS_R) { xml.workbookPr(:date1904=>@@date1904) #<x:workbookProtection workbookPassword="xsd:hexBinary data" lockStructure="1" lockWindows="1" /> xml.sheets { @worksheets.each_with_index do |sheet, index| xml.sheet(:name=>sheet.name, :sheetId=>index+1, :"r:id"=>sheet.rId) end } } end - builder.to_xml(:indent=>0) + builder.to_xml(:save_with => 0) end end end