<commit_before>#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook

#A Simple Workbook

wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
  sheet.add_row ["First Column", "Second", "Third"]
  sheet.add_row [1, 2, 3]
end

#Using Custom Styles

wb.styles do |s|
  black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
  blue_cell =  s.add_style  :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
  wb.add_worksheet(:name => "Custom Styles") do |sheet|
    sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
    sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
  end
end

#Using Custom Border Styles

wb.styles do |s|
  red_border =  s.add_style :border => {:style=>:thin, :color =>"FFFF0000"}
  blue_border =  s.add_style :border => {:style=>:thin, :color =>"FF0000FF"}

  wb.add_worksheet(:name => "Custom Borders") do |sheet|
    sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
    sheet.add_row [1, 2, 3], :style => blue_border
  end
end


##Using Custom Formatting and date1904
require 'date'
wb.styles do |s|
  date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
  padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
  percent = s.add_style(:format_code => "###0%", :border => Axlsx::STYLE_THIN_BORDER)
  # wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
  wb.add_worksheet(:name => "Formatting Data") do |sheet|
    sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
    sheet.add_row [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
  end
end


##Add an Image

wb.add_worksheet(:name => "Images") do |sheet|
  img = File.expand_path('../image1.jpeg', __FILE__)
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
    image.width=720
    image.height=666
    image.start_at 2, 2
  end
end

##Add an Image with a hyperlink

wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
  img = File.expand_path('../image1.jpeg', __FILE__)
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
    image.width=720
    image.height=666
    image.hyperlink.tooltip = "Labeled Link"
    image.start_at 2, 2
  end
end

##Asian Language Support

wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
  sheet.add_row ["日本語"]
  sheet.add_row ["华语/華語"]
  sheet.add_row ["한국어/조선말"]
end

##Styling Columns

wb.styles do |s|
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Styling Columns") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
  end
end

##Hiding Columns

wb.styles do |s|
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Hidden Column") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
    sheet.column_info[1].hidden = true
  end
end

##Styling Rows

wb.styles do |s|
  head = s.add_style :bg_color => "00", :fg_color => "FF"
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Styling Rows") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
    sheet.row_style 0, head
  end
end

##Styling Cell Overrides

wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
  # cell level style overides when adding cells
  sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
  # cell level style overrides via sheet range
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
  sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
end

##Using formula

wb.add_worksheet(:name => "Using Formulas") do |sheet|
  sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
end

##Automatic cell types

wb.add_worksheet(:name => "Automatic cell types") do |sheet|
  sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
  sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
end

##Merging Cells.

wb.add_worksheet(:name => 'Merging Cells') do |sheet|
  # cell level style overides when adding cells
  sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
  sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
  sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
  sheet.merge_cells("A4:C4")
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
  sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
end

##Generating A Bar Chart

wb.add_worksheet(:name => "Bar Chart") do |sheet|
  sheet.add_row ["A Simple Bar Chart"]
  sheet.add_row ["First", "Second", "Third"]
  sheet.add_row [1, 2, 3]
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
    chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
  end
end

##Hide Gridlines in chart
wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
  sheet.add_row ["A Simple Bar Chart"]
  sheet.add_row ["First", "Second", "Third"]
  sheet.add_row [1, 2, 3]
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
    chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
    chart.valAxis.gridlines = false
    chart.catAxis.gridlines = false
  end<commit_msg>update examples to show date time formatting and axis label rotation for charts<commit_after>#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook

#A Simple Workbook

wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
  sheet.add_row ["First Column", "Second", "Third"]
  sheet.add_row [1, 2, 3]
end

#Using Custom Styles

wb.styles do |s|
  black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
  blue_cell =  s.add_style  :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
  wb.add_worksheet(:name => "Custom Styles") do |sheet|
    sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
    sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
  end
end

#Using Custom Border Styles

wb.styles do |s|
  red_border =  s.add_style :border => {:style=>:thin, :color =>"FFFF0000"}
  blue_border =  s.add_style :border => {:style=>:thin, :color =>"FF0000FF"}

  wb.add_worksheet(:name => "Custom Borders") do |sheet|
    sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
    sheet.add_row [1, 2, 3], :style => blue_border
  end
end


##Using Custom Formatting and date1904
require 'date'
wb.styles do |s|
  date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
  padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
  percent = s.add_style(:format_code => "###0%", :border => Axlsx::STYLE_THIN_BORDER)
  # wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
  wb.add_worksheet(:name => "Formatting Data") do |sheet|
    sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
    sheet.add_row [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
  end
end


##Add an Image

wb.add_worksheet(:name => "Images") do |sheet|
  img = File.expand_path('../image1.jpeg', __FILE__)
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
    image.width=720
    image.height=666
    image.start_at 2, 2
  end
end

##Add an Image with a hyperlink

wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
  img = File.expand_path('../image1.jpeg', __FILE__)
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
    image.width=720
    image.height=666
    image.hyperlink.tooltip = "Labeled Link"
    image.start_at 2, 2
  end
end

##Asian Language Support

wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
  sheet.add_row ["日本語"]
  sheet.add_row ["华语/華語"]
  sheet.add_row ["한국어/조선말"]
end

##Styling Columns

wb.styles do |s|
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Styling Columns") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
  end
end

##Hiding Columns

wb.styles do |s|
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Hidden Column") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
    sheet.column_info[1].hidden = true
  end
end

##Styling Rows

wb.styles do |s|
  head = s.add_style :bg_color => "00", :fg_color => "FF"
  percent = s.add_style :num_fmt => 9
  wb.add_worksheet(:name => "Styling Rows") do |sheet|
    sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
    sheet.add_row [1, 2, 0.3, 4]
    sheet.add_row [1, 2, 0.2, 4]
    sheet.add_row [1, 2, 0.1, 4]
    sheet.col_style 2, percent, :row_offset => 1
    sheet.row_style 0, head
  end
end

##Styling Cell Overrides

wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
  # cell level style overides when adding cells
  sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
  # cell level style overrides via sheet range
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
  sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
end

##Using formula

wb.add_worksheet(:name => "Using Formulas") do |sheet|
  sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
end

##Automatic cell types

wb.add_worksheet(:name => "Automatic cell types") do |sheet|
  sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
  date_format = wb.styles.add_style :format_code => 'YYYY-MMM-DD'
  time_format = wb.styles.add_style :format_code => 'HH:MM:SS'
  sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1], :style => [date_format, time_format, nil, nil, nil, nil]
end

##Merging Cells.

wb.add_worksheet(:name => 'Merging Cells') do |sheet|
  # cell level style overides when adding cells
  sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
  sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
  sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
  sheet.merge_cells("A4:C4")
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
  sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
end

##Generating A Bar Chart

wb.add_worksheet(:name => "Bar Chart") do |sheet|
  sheet.add_row ["A Simple Bar Chart"]
  sheet.add_row ["First", "Second", "Third"]
  sheet.add_row [1, 2, 3]
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
    chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
    chart.valAxis.label_rotation = -45
    chart.catAxis.label_rotation = 45
  end
end

##Hide Gridlines in chart
wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
  sheet.add_row ["A Simple Bar Chart"]
  sheet.add_row ["First", "Second", "Third"]
  sheet.add_row [1, 2, 3]
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
    chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
    chart.valAxis.gridlines = false
    chart.catAxis.gridlines = false
  end
{'fraction_non_alphanumeric': 0.18423597678916828, 'fraction_numerical': 0.037395228884590584, 'mean_word_length': 4.052524429967427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 148, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107007', 'n_tokens_mistral': 5306, 'n_tokens_neox': 4941, 'n_words': 1288}