diff options
| author | Randy Morgan <[email protected]> | 2011-11-29 14:57:08 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-29 14:57:08 +0900 |
| commit | 25a73b821d4234e0a435fbee07f449c1a15ea1f4 (patch) | |
| tree | 299faa8cf2a416212cfda463d1d2e6d56727ec4d /lib | |
| parent | 51a57d7ef89ab5c5eea4341d8e3728fbf9d560f9 (diff) | |
| download | caxlsx-25a73b821d4234e0a435fbee07f449c1a15ea1f4.tar.gz caxlsx-25a73b821d4234e0a435fbee07f449c1a15ea1f4.zip | |
prepping for 1.0.10 release and travis integration
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/ar.rb | 85 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/version.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 13 |
5 files changed, 4 insertions, 101 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index da6874de..44cc9055 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -16,9 +16,6 @@ require 'axlsx/drawing/drawing.rb' require 'axlsx/workbook/workbook.rb' require 'axlsx/package.rb' -require 'axlsx/ar.rb' - - #required gems require 'Nokogiri' require 'active_support/core_ext/object/instance_variables' diff --git a/lib/axlsx/ar.rb b/lib/axlsx/ar.rb deleted file mode 100644 index 2f11228a..00000000 --- a/lib/axlsx/ar.rb +++ /dev/null @@ -1,85 +0,0 @@ -# ActsAsAxlsx -require 'axlsx' -module Axlsx - # Mixing module for adding acts_as_axlsx to active record base - module Ar - - # Extents active record with this ojbects class method acts_as_axlsx - def self.included(base) - base.send :extend, ClassMethods - end - - # Class methods for the mixin - module ClassMethods - - # adds in the instance and singleton methods - def acts_as_axlsx(options={}) - @xlsx_reject = options.delete(:reject) || [] - @xlsx_only = options.delete(:only) || [] - @xlsx_methods = options.delete(:methods) || [] - @i18n = options.delete(:i18n) || false - include Axlsx::Ar::InstanceMethods - extend Axlsx::Ar::SingletonMethods - end - end - - # Singleton methods for the mixin - module SingletonMethods - - # Maps the AR class to an Axlsx package - # options are passed into AR find - # @param [Symbol, Integer] :all, :first, id etc. - # @option options [Integer] header_style to apply to the first row of field names - # @option options [Array, Symbol] an array of Axlsx types for each cell in data rows or a single type that will be applied to all types. - # @option options [Integer, Array] style The style to pass to Worksheet#add_row - # @option options [Array] reject The names fo columns to exclude from the report - # @see Worksheet#add_row - def to_xlsx(number = :all, options = {}) - row_style = options.delete(:style) - header_style = options.delete(:header_style) || row_style - types = options.delete(:types) - @xlsx_reject << options.delete(:reject) unless options[:reject].nil? - - - p = Package.new - row_style = p.workbook.styles.add_style(row_style) unless row_style.nil? - header_style = p.workbook.styles.add_style(header_style) unless header_style.nil? - - data = [*find(number, options)] - data.compact! - data.flatten! - return p if data.empty? - @xlsx_columns = data.first.attributes.keys - @xlsx_reject.map { |r| r = r.to_s } - p.workbook.add_worksheet(:name=>table_name.humanize) do |sheet| - col_labels = @i18n == false ? @xlsx_columns : @xlsx_columns.map { |c| I18n.t("#{@i18n}.#{self.name.underscore}.#{c}") } - - sheet.add_row col_labels, :style=>header_style - data.each do |r| - row_data = @xlsx_columns.map { |c| r.attributes[c] } - sheet.add_row row_data, :style=>row_style, :types=>types - end - end - p - end - end - - # Empty module - I really like ruports way of allowing :include, :only, :exclude - # and am looking to add something like that in the next release - module InstanceMethods - def to_xlsx(options={}) - self.class.to_xlsx(self.id, options) - end - end - - - end - -end -begin -require 'active_record' -ActiveRecord::Base.send :include, Axlsx::Ar -rescue Exception=>e - puts "Running without active record extensions" -end - - diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index e06a4026..6b64fb30 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -258,7 +258,7 @@ module Axlsx @numFmts.lock @fonts = SimpleTypedList.new Font - @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1) + @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1, :numFmt=>"0") @fonts.lock @fills = SimpleTypedList.new Fill diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index b0681d8c..92993f79 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,4 +1,4 @@ module Axlsx # version - VERSION="1.0.10a" + VERSION="1.0.10" end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 556a5a89..716b75a4 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -167,8 +167,8 @@ module Axlsx # About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values. # @see Axlsx#date1904 def cast_value(v) - if @type == :time && v.is_a?(Time) - #todo consider a time parsing method to convert strings to time + if (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time)) + v = v.to_time epoc = Workbook.date1904 ? Time.local(1904,1,1,0,0,0,0,v.zone) : Time.local(1900,1,1,0,0,0,0,v.zone) ((v - epoc) /60.0/60.0/24.0).to_f elsif @type == :float @@ -178,15 +178,6 @@ module Axlsx else @type = :string v.to_s - # curious as to why this would be the cells responsibility - # convert your values before passing them in wankers! CGI.unescapeHTML(v.to_s).to_xs - # to revert, load this once when the gem is loaded. - # unless String.method_defined? :to_xs - # require 'fast_xs' #dep - # class String - # alias_method :to_xs, :fast_xs - # end - # end end end end |
