Sha256: 1a9a57c5e44109e4558393d91a9aa30b4b8296d819a0c16f9f47aa3d9f2caa3d

Contents?: true

Size: 1.44 KB

Versions: 12

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

#######################################################################
#
# An example showing all 48 default chart styles available in Excel 2007
# using Excel::Writer::XLSX.. Note, these styles are not the same as the
# styles available in Excel 2013.
#
# reverse ('(c)'), March 2015, John McNamara, jmcnamara@cpan.org
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
#

require 'write_xlsx'

workbook  = WriteXLSX.new('chart_styles.xlsx')

# Show the styles for all of these chart types.
chart_types = ['column', 'area', 'line', 'pie']


chart_types.each do |chart_type|
  # Add a worksheet for each chart type.
  worksheet = workbook.add_worksheet(chart_type.capitalize)
  worksheet.zoom = 30
  style_number = 1

  # Create 48 charts, each with a different style.
  0.step(89, 15) do |row_num|
    0.step(63, 8) do |col_num|
      chart = workbook.add_chart(
        :type     => chart_type,
        :embedded => 1
      )

      chart.add_series( :values => '=Data!$A$1:$A$6' )
      chart.set_title( :name => "Style #{style_number}" )
      chart.set_legend( :none => 1 )
      chart.set_style( style_number )

      worksheet.insert_chart(row_num, col_num, chart)
      style_number += 1
    end
  end
end

# Create a worksheet with data for the charts.
data = [ 10, 40, 50, 20, 10, 50 ]
data_worksheet = workbook.add_worksheet('Data')
data_worksheet.write_col('A1', data)
data_worksheet.hide

workbook.close

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
write_xlsx-1.09.4 examples/chart_styles.rb
write_xlsx-1.09.3 examples/chart_styles.rb
write_xlsx-1.09.2 examples/chart_styles.rb
write_xlsx-1.09.1 examples/chart_styles.rb
write_xlsx-1.09.0 examples/chart_styles.rb
write_xlsx-1.08.2 examples/chart_styles.rb
write_xlsx-1.08.1 examples/chart_styles.rb
write_xlsx-1.08.0 examples/chart_styles.rb
write_xlsx-1.07.0 examples/chart_styles.rb
write_xlsx-1.04.0 examples/chart_styles.rb
write_xlsx-1.02.0 examples/chart_styles.rb
write_xlsx-1.01.0 examples/chart_styles.rb