diff options
| author | Sean Duckett <[email protected]> | 2012-03-14 10:26:16 -0500 |
|---|---|---|
| committer | Sean Duckett <[email protected]> | 2012-03-14 10:26:16 -0500 |
| commit | 0979748ef9e0b701f6d903e680b65c0324839a60 (patch) | |
| tree | 1c359fbe688816ced5e140296fce3edfc09a11cf | |
| parent | d86e4fa46fb3aa1d73aac3056e810e27a6a1a16e (diff) | |
| parent | c7d715dea1e3829ea5110ec8bb4388f2633bf92a (diff) | |
| download | caxlsx-0979748ef9e0b701f6d903e680b65c0324839a60.tar.gz caxlsx-0979748ef9e0b701f6d903e680b65c0324839a60.zip | |
Merge branch 'master' of https://github.com/randym/axlsx
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | axlsx.gemspec | 4 | ||||
| -rw-r--r-- | examples/example.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/axis.rb | 29 | ||||
| -rw-r--r-- | lib/axlsx/drawing/graphic_frame.rb | 12 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 45 | ||||
| -rw-r--r-- | lib/axlsx/util/constants.rb | 27 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 25 | ||||
| -rw-r--r-- | test/content_type/tc_content_type.rb | 48 | ||||
| -rw-r--r-- | test/stylesheet/tc_styles.rb | 4 | ||||
| -rw-r--r-- | test/tc_package.rb | 20 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 5 |
14 files changed, 140 insertions, 92 deletions
@@ -353,6 +353,8 @@ Please see the {file:CHANGELOG.md} document for past release information. [jurriaan](https://github.com/jurriaan) - for showing there is more than one way to skin a cat, and work with rows while you are at it. +[joekain](https://github.com/joekain) - for keeping our refereneces working even in the double digits! + #Copyright and License ---------- diff --git a/axlsx.gemspec b/axlsx.gemspec index 0cfa52bd..c8fda02f 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -24,8 +24,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'rubyzip', '~> 0.9' - s.add_runtime_dependency 'rake', "0.8.7" if RUBY_VERSION == "1.9.2" - s.add_runtime_dependency 'rake', "~> 0.9" if ["1.9.3", "1.8.7"].include?(RUBY_VERSION) + s.add_runtime_dependency 'rake', '0.8.7' if RUBY_VERSION == "1.9.2" + s.add_runtime_dependency 'rake', '>= 0.8.7' if ["1.9.3", "1.8.7"].include?(RUBY_VERSION) s.add_development_dependency 'yard' s.add_development_dependency 'yard' s.add_development_dependency 'rdiscount' diff --git a/examples/example.rb b/examples/example.rb index 8058b50b..df5a401f 100644 --- a/examples/example.rb +++ b/examples/example.rb @@ -201,6 +201,13 @@ wb.add_worksheet(:name => "custom column widths") do |sheet| sheet.column_widths nil, 3 end + +##Hide Gridlines in worksheet +wb.add_worksheet(:name => "No Gridlines") do |sheet| + sheet.add_row ["This", "Sheet", "Hides", "Gridlines"] + sheet.show_gridlines = false +end + ##Specify Page Margins for printing margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7} wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet| diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 1dfdbd92..8b8fb7c5 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -60,7 +60,7 @@ module Axlsx val[:i] += ((c.bytes.first - 65) + val[:base]); val[:base] *= 26; val end - [v[:i]-1, ((name[/[1-9]+/]).to_i)-1] + [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1] end end diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb index ad550269..183cbcad 100644 --- a/lib/axlsx/drawing/axis.rb +++ b/lib/axlsx/drawing/axis.rb @@ -3,7 +3,7 @@ module Axlsx # the access class defines common properties and values for a chart axis. class Axis - # the id of the axis. + # the id of the axis. # @return [Integer] attr_reader :axId @@ -15,7 +15,7 @@ module Axlsx # @see Scaling # @return [Scaling] attr_reader :scaling - + # The position of the axis # must be one of [:l, :r, :t, :b] # @return [Symbol] @@ -34,7 +34,11 @@ module Axlsx # specifies how the perpendicular axis is crossed # must be one of [:autoZero, :min, :max] # @return [Symbol] - attr_reader :crosses + attr_reader :crosses + + # specifies if gridlines should be shown in the chart + # @return [Boolean] + attr_reader :gridlines # Creates an Axis object # @param [Integer] axId the id of this axis @@ -49,11 +53,12 @@ module Axlsx @axId = axId @crossAx = crossAx @format_code = "General" - @scaling = Scaling.new(:orientation=>:minMax) + @scaling = Scaling.new(:orientation=>:minMax) self.axPos = :b self.tickLblPos = :nextTo self.format_code = "General" self.crosses = :autoZero + self.gridlines = true options.each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end @@ -70,6 +75,10 @@ module Axlsx # default :General def format_code=(v) Axlsx::validate_string(v); @format_code = v; end + # Specify if gridlines should be shown for this axis + # default true + def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end + # specifies how the perpendicular axis is crossed # must be one of [:autoZero, :min, :max] def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end @@ -82,13 +91,21 @@ module Axlsx @scaling.to_xml(xml) xml.delete :val=>0 xml.axPos :val=>@axPos - xml.majorGridlines + xml.majorGridlines { + if self.gridlines == false + xml.spPr { + xml[:a].ln { + xml[:a].noFill + } + } + end + } xml.numFmt :formatCode => @format_code, :sourceLinked=>"1" xml.majorTickMark :val=>"none" xml.minorTickMark :val=>"none" xml.tickLblPos :val=>@tickLblPos xml.crossAx :val=>@crossAx xml.crosses :val=>@crosses - end + end end end diff --git a/lib/axlsx/drawing/graphic_frame.rb b/lib/axlsx/drawing/graphic_frame.rb index 903ff1d6..178e0ea8 100644 --- a/lib/axlsx/drawing/graphic_frame.rb +++ b/lib/axlsx/drawing/graphic_frame.rb @@ -17,14 +17,14 @@ module Axlsx # @param [TwoCellAnchor] anchor # @param [Class] chart_type def initialize(anchor, chart_type, options) - DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type + DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type @anchor = anchor @chart = chart_type.new(self, options) end # The relationship id for this graphic # @return [String] - def rId + def rId "rId#{@anchor.index+1}" end @@ -32,10 +32,10 @@ module Axlsx # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. # @return [String] def to_xml(xml) - xml.graphicFrame { + xml.graphicFrame { xml.nvGraphicFramePr { - xml.cNvPr :id=>2, :name=>chart.title - xml.cNvGraphicFramePr + xml.cNvPr :id=>2, :name=>chart.title.text + xml.cNvGraphicFramePr } xml.xfrm { xml[:a].off(:x=>0, :y=>0) @@ -47,7 +47,7 @@ module Axlsx } } } - + end end end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 955a8b1e..cb40ee74 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -120,7 +120,7 @@ module Axlsx end # Drastically simplifies style creation and management. - # @return [Integer] + # @return [Integer] # @option options [String] fg_color The text color # @option options [Integer] sz The text size # @option options [Boolean] b Indicates if the text should be bold @@ -133,13 +133,13 @@ module Axlsx # @option options [String] font_name The name of the font to use # @option options [Integer] num_fmt The number format to apply # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored. - # @option options [Integer] border The border style to use. + # @option options [Integer] border The border style to use. # @option options [String] bg_color The background color to apply to the cell # @option options [Boolean] hidden Indicates if the cell should be hidden # @option options [Boolean] locked Indicates if the cell should be locked # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment # @see CellAlignment - # + # # @example You Got Style # require "rubygems" # if that is your preferred way to manage gems! # require "axlsx" @@ -165,15 +165,15 @@ module Axlsx # ws = p.workbook.add_worksheet # # # define your styles - # title = ws.style.add_style(:bg_color => "FFFF0000", + # title = ws.style.add_style(:bg_color => "FFFF0000", # :fg_color=>"#FF000000", - # :border=>Axlsx::STYLE_THIN_BORDER, + # :border=>Axlsx::STYLE_THIN_BORDER, # :alignment=>{:horizontal => :center}) # # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS, # :border=>Axlsx::STYLE_THIN_BORDER) # - # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT, + # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT, # :border=>Axlsx::STYLE_THIN_BORDER) # # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0", @@ -190,7 +190,7 @@ module Axlsx # f = File.open('example_you_got_style.xlsx', 'w') # p.serialize(f) def add_style(options={}) - + numFmtId = if options[:format_code] n = @numFmts.map{ |f| f.numFmtId }.max + 1 numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code]) @@ -198,19 +198,19 @@ module Axlsx else options[:num_fmt] || 0 end - + borderId = options[:border] || 0 raise ArgumentError, "Invalid borderId" unless borderId < borders.size - + fill = if options[:bg_color] color = Color.new(:rgb=>options[:bg_color]) pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color) - fills << Fill.new(pattern) + fills << Fill.new(pattern) else 0 end - + fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length) font = Font.new() [:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? } @@ -218,27 +218,28 @@ module Axlsx font.name = options[:font_name] unless options[:font_name].nil? fonts << font else - 0 + 0 end - + applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0 - + xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection) xf.applyNumberFormat = true if xf.numFmtId > 0 xf.applyBorder = true if borderId > 0 - + if options[:alignment] xf.alignment = CellAlignment.new(options[:alignment]) + xf.applyAlignment = true end - + if applyProtection xf.protection = CellProtection.new(options) end - + cellXfs << xf end - + # Serializes the styles document # @return [String] def to_xml() @@ -253,7 +254,7 @@ module Axlsx end private - # Creates the default set of styles the exel requires to be valid as well as setting up the + # Creates the default set of styles the exel requires to be valid as well as setting up the # Axlsx::STYLE_THIN_BORDER def load_default_styles @numFmts = SimpleTypedList.new NumFmt, 'numFmts' @@ -274,8 +275,8 @@ module Axlsx @borders = SimpleTypedList.new Border, 'borders' @borders << Border.new black_border = Border.new - [:left, :right, :top, :bottom].each do |item| - black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000")) + [:left, :right, :top, :bottom].each do |item| + black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000")) end @borders << black_border @borders.lock @@ -300,4 +301,4 @@ module Axlsx end end end - + diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index e9a0a02a..bdda9216 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -21,7 +21,7 @@ module Axlsx # dc elements (core) namespace CORE_NS_DC = "http://purl.org/dc/elements/1.1/" - + # dcmit (core) namespcace CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/" @@ -30,10 +30,10 @@ module Axlsx # xml schema namespace CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance" - + # spreadsheet drawing namespace XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" - + # drawing namespace XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main" @@ -43,13 +43,12 @@ module Axlsx # relationships namespace XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" - # relationships name space RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships" # table rels namespace TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" - + # workbook rels namespace WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" @@ -80,7 +79,7 @@ module Axlsx # image rels namespace HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" - # table content type + # table content type TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml" # workbook content type @@ -90,14 +89,14 @@ module Axlsx APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml" # rels content type - RELS_CT = "application/vnd.openxmlformats-package.relationships+xml" + RELS_CT = "application/vnd.openxmlformats-package.relationships+xml" # styles content type STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" # xml content type XML_CT = "application/xml" - + # worksheet content type WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" @@ -127,7 +126,7 @@ module Axlsx # jpeg extension JPEG_EX = "jpeg" - + # gif extension GIF_EX = "gif" @@ -145,10 +144,10 @@ module Axlsx # shared_strings part SHARED_STRINGS_PN = "sharedStrings.xml" - + # app part APP_PN = "docProps/app.xml" - + # core part CORE_PN = "docProps/core.xml" @@ -196,12 +195,12 @@ module Axlsx # spreadsheetML validation schema SML_XSD = SCHEMA_BASE + "sml.xsd" - + # drawing validation schema DRAWING_XSD = SCHEMA_BASE + "dml-spreadsheetDrawing.xsd" # number format id for pecentage formatting using the default formatting id. - NUM_FMT_PERCENT = 9 + NUM_FMT_PERCENT = 9 # number format id for date format like 2011/11/13 NUM_FMT_YYYYMMDD = 100 @@ -216,7 +215,7 @@ module Axlsx STYLE_DATE = 2 # error messages RestrictionValidor - ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s." + ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s." # error message DataTypeValidator ERR_TYPE = "Invalid Data %s for %s. must be %s." diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 62fa539f..ff759cdf 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -230,7 +230,7 @@ module Axlsx # @example Absolute Cell Reference # ws.rows.first.cells.first.r #=> "$A$1" def r_abs - "$#{r.split('').join('$')}" + "$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}" end # @return [Integer] The cellXfs item index applied to this cell. diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 679817ce..a514c31c 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -35,6 +35,10 @@ module Axlsx # @return Array attr_reader :auto_filter + # Indicates if the worksheet should show gridlines or not + # @return Boolean + attr_reader :show_gridlines + # Page margins for printing the worksheet. # @example # wb = Axlsx::Package.new.workbook @@ -55,6 +59,7 @@ module Axlsx @page_margins ||= PageMargins.new yield @page_margins if block_given? @page_margins + end # Creates a new worksheet. @@ -62,8 +67,10 @@ module Axlsx # @see Workbook#add_worksheet # @option options [String] name The name of this worksheet. # @option options [Hash] page_margins A hash containing page margins for this worksheet. @see PageMargins + # @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet. def initialize(wb, options={}) @drawing = @page_margins = @auto_filter = nil + @show_gridlines = true @rows = SimpleTypedList.new Row self.workbook = wb @workbook.worksheets << self @@ -109,6 +116,14 @@ module Axlsx "#{rows.first.cells.first.r}:#{rows.last.cells.last.r}" end + # Indicates if gridlines should be shown in the sheet. + # This is true by default. + # @return [Boolean] + def show_gridlines=(v) + Axlsx::validate_boolean v + @show_gridlines = v + end + # Returns the cell or cells defined using excel style A1:B3 references. # @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber @@ -337,11 +352,11 @@ module Axlsx # this is required by rubyXL, spec says who cares - but it seems they didnt notice # however, it also seems to be causing some odd [Grouped] stuff in excel 2011 - so # removing until I understand it better. - # xml.sheetViews { - # xml.sheetView(:tabSelected => 1, :workbookViewId => 0) { - # xml.selection :activeCell=>"A1", :sqref => "A1" - # } - # } + xml.sheetViews { + xml.sheetView(:tabSelected => 1, :workbookViewId => 0, :showGridLines => show_gridlines) { + xml.selection :activeCell=>"A1", :sqref => "A1" + } + } if @auto_fit_data.size > 0 xml.cols { diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb index 9fcbcd70..5757b980 100644 --- a/test/content_type/tc_content_type.rb +++ b/test/content_type/tc_content_type.rb @@ -4,7 +4,7 @@ require 'test/unit' require 'axlsx.rb' class TestContentType < Test::Unit::TestCase - def setup + def setup @package = Axlsx::Package.new @doc = Nokogiri::XML(@package.send(:content_types).to_xml) end @@ -21,63 +21,63 @@ class TestContentType < Test::Unit::TestCase def test_pre_built_types - o_path = "Types Override [@ContentType='%s']" - d_path = "Types Default [@ContentType='%s']" + o_path = "//xmlns:Override[@ContentType='%s']" + d_path = "//xmlns:Default[@ContentType='%s']" - #default - assert_equal(@doc.css("Types Default").size, 2, "There should be 2 default types") - - node = @doc.css(d_path % Axlsx::XML_CT).first + #default + assert_equal(@doc.xpath("//xmlns:Default").size, 2, "There should be 2 default types") + + node = @doc.xpath(d_path % Axlsx::XML_CT).first assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid") - node = @doc.css(d_path % Axlsx::RELS_CT).first + node = @doc.xpath(d_path % Axlsx::RELS_CT).first assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid") #overrride - assert_equal(@doc.css("Types Override").size, 4, "There should be 4 Override types") + assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types") - node = @doc.css(o_path % Axlsx::APP_CT).first + node = @doc.xpath(o_path % Axlsx::APP_CT).first assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid") - node = @doc.css(o_path % Axlsx::CORE_CT).first + node = @doc.xpath(o_path % Axlsx::CORE_CT).first assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid") - node = @doc.css(o_path % Axlsx::STYLES_CT).first + node = @doc.xpath(o_path % Axlsx::STYLES_CT).first assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid") - node = @doc.css(o_path % Axlsx::WORKBOOK_CT).first + node = @doc.xpath(o_path % Axlsx::WORKBOOK_CT).first assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid") end def test_should_get_worksheet_for_worksheets - o_path = "Types Override [@ContentType='%s']" + o_path = "//xmlns:Override[@ContentType='%s']" ws = @package.workbook.add_worksheet doc = Nokogiri::XML(@package.send(:content_types).to_xml) - assert_equal(doc.css("Types Override").size, 5, "adding a worksheet should add another type") - assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid") + assert_equal(doc.xpath("//xmlns:Override").size, 5, "adding a worksheet should add another type") + assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid") ws = @package.workbook.add_worksheet doc = Nokogiri::XML(@package.send(:content_types).to_xml) - assert_equal(doc.css("Types Override").size, 6, "adding workship should add another type") - assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid") + assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type") + assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid") end def test_drawings_and_charts_need_content_types - o_path = "Types Override [@ContentType='%s']" + o_path = "//xmlns:Override[@ContentType='%s']" ws = @package.workbook.add_worksheet c = ws.add_chart Axlsx::Pie3DChart doc = Nokogiri::XML(@package.send(:content_types).to_xml) - assert_equal(doc.css("Types Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}") - assert_equal(doc.css(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid") - assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid") + assert_equal(doc.xpath("//xmlns:Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}") + assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid") + assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid") c = ws.add_chart Axlsx::Pie3DChart doc = Nokogiri::XML(@package.send(:content_types).to_xml) - assert_equal(doc.css("Types Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}") - assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid") + assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}") + assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid") end end diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index df180b61..1b7365b2 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -49,8 +49,8 @@ class TestStyles < Test::Unit::TestCase assert_equal(xf.applyProtection, 1, "protection applied") assert_equal(xf.applyBorder, true, "border applied") - assert_equal(xf.applyNumberFormat, true, "border applied") - + assert_equal(xf.applyNumberFormat, true, "number format applied") + assert_equal(xf.applyAlignment, true, "alignment applied") end end diff --git a/test/tc_package.rb b/test/tc_package.rb index 7057badd..a3f2bef5 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -2,7 +2,7 @@ require 'test/unit' require 'axlsx.rb' class TestPackage < Test::Unit::TestCase - def setup + def setup @package = Axlsx::Package.new ws = @package.workbook.add_worksheet chart = ws.add_chart Axlsx::Pie3DChart @@ -39,16 +39,16 @@ class TestPackage < Test::Unit::TestCase fname = 'axlsx_test_serialization.xlsx' assert_nothing_raised do begin - z= @package.serialize(@fname) + z= @package.serialize(@fname) zf = Zip::ZipFile.open(@fname) @package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } - File.delete(@fname) + File.delete(@fname) rescue Errno::EACCES puts "WARNING:: test_serialization requires write access." end - end + end end - + def test_validation assert_equal(@package.validate.size, 0, @package.validate) #how to test for failure? the internal validations on the models are so strict I cant break anthing..... @@ -58,7 +58,7 @@ class TestPackage < Test::Unit::TestCase p = @package.send(:parts) p.each do |part| #all parts must have :doc, :entry, :schema - assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?) + assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?) end #all parts have an entry assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing") @@ -76,7 +76,7 @@ class TestPackage < Test::Unit::TestCase #no mystery parts assert_equal(p.size, 12) - + end def test_shared_strings_requires_part @@ -84,7 +84,7 @@ class TestPackage < Test::Unit::TestCase p = @package.send(:parts) assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing") end - + def test_workbook_is_a_workbook assert @package.workbook.is_a? Axlsx::Workbook end @@ -106,4 +106,8 @@ class TestPackage < Test::Unit::TestCase assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1) end + def test_name_to_indices + assert(Axlsx::name_to_indices('A1') == [0,0]) + assert(Axlsx::name_to_indices('A100') == [0,99], 'needs to axcept rows that contain 0') + end end diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 97a9951b..e111f7cd 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -9,6 +9,9 @@ class TestCell < Test::Unit::TestCase p.workbook.styles.add_style :sz=>20 @row = @ws.add_row @c = @row.add_cell 1, :type=>:float, :style=>1 + data = (0..26).map { |index| index } + @ws.add_row data + @cAA = @ws["AA2"] end def test_initialize @@ -18,7 +21,6 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.value, 1.0, "type option is applied and value is casted") end - def test_style_date_data c = Axlsx::Cell.new(@c.row, Time.now) assert_equal(Axlsx::STYLE_DATE, c.style) @@ -42,6 +44,7 @@ class TestCell < Test::Unit::TestCase def test_r_abs assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference") + assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns") end def test_style |
