lib/axlsx/package.rb
# Serialize your workbook to disk as an xlsx document.
#
# @param [String] output The name of the file you want to serialize your package to
# @param [Boolean] confirm_valid Validate the package prior to serialization.
# @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
# @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
#   confirm_valid should be used in the rare case that you cannot open the serialized file.
# @see Package#validate
# @example
#   # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts.
#   # Take a look at the README for an example of how to do it!
#
#   #serialize to a file
#   p = Axlsx::Package.new
#   # ......add cool stuff to your workbook......
#   p.serialize("example.xlsx")
#
#   # Serialize to a stream
#   s = p.to_stream()
#   File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
Serialize your workbook to disk as an xlsx document.
Serialize your workbook to disk as an xlsx document .
def serialize(output, confirm_valid=false)
      return false unless !confirm_valid || self.validate.empty?
      Zip::ZipOutputStream.open(output) do |zip|
        write_parts(zip)
      end
      true
    end
def serialize ( output , confirm_valid = false ) return false unless ! confirm_valid || self . validate . empty? Zip :: ZipOutputStream . open ( output ) do | zip | write_parts ( zip ) end true end
Serialize your workbook to disk as an xlsx document.
Serialize your workbook to disk as an xlsx document .
False if confirm_valid and validation errors exist. True if the package was serialized
False if confirm_valid and validation errors exist . True if the package was serialized
Boolean
output
confirm_valid
confirm_valid Validate the package prior to serialization.
confirm_valid Validate the package prior to serialization .
note
A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents. confirm_valid should be used in the rare case that you cannot open the serialized file.
A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents . confirm_valid should be used in the rare case that you cannot open the serialized file .
see
None
example
This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts. # Take a look at the README for an example of how to do it. #serialize to a file p = Axlsx::Package.new # ......add cool stuff to your workbook...... p.serialize("example.xlsx") # Serialize to a stream s = p.to_stream() File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
This is how easy it is to create a valid xlsx file . Of course you might want to add a sheet or two and maybe some data styles and charts . # Take a look at the README for an example of how to do it . #serialize to a file p = Axlsx :: Package . new # ...... add cool stuff to your workbook ...... p . serialize ( " example . xlsx " ) # Serialize to a stream s = p . to_stream () File . open ( ' example_streamed . xlsx ' ' w ' ) { |f| f . write ( s . read ) }