Sha256: ab70862a044d98c466314dcc25ee092e0c1db75a0f8665d71318bb1344e4333f

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 KB

Contents

require 'spreadsheet'

##
# 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
    unless instance_methods.include? "new_format_column"
      alias :new_format_column :format_column
      def format_column column, width=nil, format=nil
        if width.is_a? Format
          new_format_column column, width, format
        else
          new_format_column column, format, :width => width
        end
      end
    end
    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
    def write_url row, col, url, string=url, format=nil
      row(row)[col] = Link.new url, string
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spreadsheet-1.3.3 lib/spreadsheet/excel.rb
spreadsheet-1.3.2 lib/spreadsheet/excel.rb
spreadsheet-1.3.1 lib/spreadsheet/excel.rb
spreadsheet-1.3.0 lib/spreadsheet/excel.rb
spreadsheet-1.2.9 lib/spreadsheet/excel.rb
spreadsheet-1.2.8 lib/spreadsheet/excel.rb
spreadsheet-1.2.7 lib/spreadsheet/excel.rb
nulogy-spreadsheet-0.6.5.7.4 lib/spreadsheet/excel.rb
nulogy-spreadsheet-0.6.5.7.3 lib/spreadsheet/excel.rb