Sha256: 1124401812b3a3b8c6234723526a32f20f1061190e95fb74e9bfbbb135654f31

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'spreadsheet'

warn <<-EOS
[DEPRECATED] By requiring 'spreadsheet/excel' you are loading a Compatibility
             layer which provides a drop-in replacement for Spreadsheet::Excel
             versions <= 0.3.5.1. This code will be removed in Spreadsheet
             version 1.0.0
EOS
##
# Spreadsheet::Excel Compatibility Layer.
# Drop-in replacement for Spreadsheet::Excel version <= 0.3.5.1
module Spreadsheet
  module Excel
    class ExcelCompatibleWorkbook < Workbook
      def initialize file_path, *args
        super *args
        @file_path = file_path
      end
      def close
        write @file_path
      end
    end
    def Excel.new file_path
      ExcelCompatibleWorkbook.new file_path
    end
    class Workbook
      def add_worksheet name
        if name.is_a? String
          create_worksheet :name => name
        else
          super
        end
      end
    end
  end
  class Worksheet
    def write row, col, data=nil, format=nil
      if data.is_a? Array
        write_row row, col, data, format
      else
        row = row(row)
        row[col] = data
        row.set_format col, format
      end
    end
    def write_column row, col, data=nil, format=nil
      if data.is_a? Array
        data.each do |token|
          if token.is_a? Array
            write_row row, col, token, format
          else
            write row, col, token, format
          end
          row += 1
        end
      else
        write row, col, data, format
      end
    end
    def write_row row, col, data=nil, format=nil
      if data.is_a? Array
        data.each do |token|
          if token.is_a? Array
            write_column row, col, token, format
          else
            write row, col, token, format
          end
          col += 1
        end
      else
        write row, col, data, format
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spreadsheet-0.6.0 lib/spreadsheet/excel.rb