Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ff5d690f8c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 88 lines (71 sloc) 3.072 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
# encoding: UTF-8
require 'axlsx/version.rb'

require 'axlsx/util/simple_typed_list.rb'
require 'axlsx/util/constants.rb'
require 'axlsx/util/validators.rb'
require 'axlsx/util/storage.rb'

#not even close to being ready but it does not break anything so it stays for now.
# needs a full re-write to use agile-encryption properly
require 'axlsx/util/cbf.rb'
require 'axlsx/util/ms_off_crypto.rb'


# to be included with parsable intitites.
#require 'axlsx/util/parser.rb'

require 'axlsx/stylesheet/styles.rb'

require 'axlsx/doc_props/app.rb'
require 'axlsx/doc_props/core.rb'
require 'axlsx/content_type/content_type.rb'
require 'axlsx/rels/relationships.rb'

require 'axlsx/drawing/drawing.rb'
require 'axlsx/workbook/workbook.rb'
require 'axlsx/package.rb'
#required gems
require 'nokogiri'
require 'zip/zip'

#core dependencies
require 'bigdecimal'
require 'time'

#if object does not have this already, I am borrowing it from active_support.
# I am a very big fan of activesupports instance_values method, but do not want to require nor include the entire
# library just for this one method.
if !Object.respond_to?(:instance_values)
  Object.send :public # patch for 1.8.7 as it uses private scope
  Object.send :define_method, :instance_values do
    Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
  end
end

# xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
module Axlsx
  # determines the cell range for the items provided
  def self.cell_range(items)
    return "" unless items.first.is_a? Cell
    ref = "'#{items.first.row.worksheet.name}'!" +
      "#{items.first.r_abs}"
    ref += ":#{items.last.r_abs}" if items.size > 1
    ref
  end

  def self.name_to_indices(name)
    raise ArgumentError, 'invalid cell name' unless name.size > 1
    v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
      val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
    end

    [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]

  end

  # converts the column index into alphabetical values.
  # @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
  # @return [String]
  def self.col_ref(index)
    chars = []
    while index >= 26 do
      chars << ((index % 26) + 65).chr
      index = index / 26 - 1
end
chars << (index + 65).chr
chars.reverse.join
end

# @return [String] The alpha(column)numeric(row) reference for this sell.
# @example Relative Cell Reference
# ws.rows.first.cells.first.r #=> "A1"
def self.cell_r(c_index, r_index)
Axlsx::col_ref(c_index).to_s << (r_index+1).to_s
end

end
Something went wrong with that request. Please try again.