Sha256: 84d8b31fbad7c090844447cc194df06024a7d88ac515f561cbdcc722e112d571

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'test_helper'

class IntegrationTest < MiniTest::Test
  # taken from /examples
  def test_table_with_borders
    axlsx = Axlsx::Package.new
    workbook = axlsx.workbook
    workbook.add_worksheet do |sheet|
      sheet.add_row
      sheet.add_row ['', 'Product', 'Category',  'Price']
      sheet.add_row ['', 'Butter', 'Dairy',      4.99]
      sheet.add_row ['', 'Bread', 'Baked Goods', 3.45]
      sheet.add_row ['', 'Broccoli', 'Produce',  2.99]
      sheet.add_row ['', 'Pizza', 'Frozen Foods',  4.99]
      sheet.column_widths 5, 20, 20, 20

      # using AxlsxStyler DSL
      sheet['B2:D2'].add_style b: true
      sheet['B2:B6'].add_style b: true
      sheet['B2:D2'].add_style bg_color: '95AFBA'
      sheet['B3:D6'].add_style bg_color: 'E2F89C'
      sheet['D3:D6'].add_style alignment: { horizontal: :left }
      sheet['B2:D6'].add_border
      sheet['B3:D3'].add_border [:top]
    end
    workbook.apply_styles
    axlsx.serialize File.expand_path(
      '../../tmp/borders_test.xlsx',
      __FILE__
    )
    assert_equal 12, workbook.style_index.count
  end

  def test_table_with_num_fmt
    axlsx = Axlsx::Package.new
    workbook = axlsx.workbook
    t = Time.now
    day = 24 * 60 * 60
    workbook.add_worksheet do |sheet|
      sheet.add_row %w(Date Count Percent)
      sheet.add_row [t - 2 * day, 2, 2.to_f / 11]
      sheet.add_row [t - 1 * day, 3, 3.to_f / 11]
      sheet.add_row [t,           6, 6.to_f / 11]

      sheet['A1:B1'].add_style b: true
      sheet['A2:A4'].add_style format_code: 'YYYY-MM-DD hh:mm:ss'
    end
    workbook.apply_styles
    assert_equal 2, workbook.style_index.count
    axlsx.serialize File.expand_path(
      '../../tmp/num_fmt_test.xlsx',
      __FILE__
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axlsx_styler-0.0.4 test/integration_test.rb