diff options
| author | Randy Morgan <[email protected]> | 2013-09-26 21:17:25 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2013-09-26 21:17:25 +0900 |
| commit | 168fcb8406d80f863d5d1b50a38e585580f89acf (patch) | |
| tree | adc9dd82aa356dcabe8396d21aa0e3926ac7b9a3 | |
| parent | 46a17e4b3fe0531ac6b2e48f818a982a86f538e4 (diff) | |
| download | caxlsx-168fcb8406d80f863d5d1b50a38e585580f89acf.tar.gz caxlsx-168fcb8406d80f863d5d1b50a38e585580f89acf.zip | |
extended examples and smooth lines for line chart
| -rw-r--r-- | axlsx.gemspec | 1 | ||||
| -rwxr-xr-x | examples/example.rb | 1 | ||||
| -rw-r--r-- | examples/merge_cells.rb | 17 | ||||
| -rw-r--r-- | examples/no_grid_with_borders.rb | 18 | ||||
| -rw-r--r-- | examples/pivot_test.rb | 63 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_chart.rb | 3 | ||||
| -rw-r--r-- | notes_on_header_footer.md | 11 | ||||
| -rw-r--r-- | test/drawing/tc_line_chart.rb | 11 |
8 files changed, 120 insertions, 5 deletions
diff --git a/axlsx.gemspec b/axlsx.gemspec index 22ee8044..ab2b35bc 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -10,6 +10,7 @@ Gem::Specification.new do |s| s.date = Time.now.strftime('%Y-%m-%d') s.summary = "excel OOXML (xlsx) with charts, styles, images and autowidth columns." s.has_rdoc = 'axlsx' + s.license = 'MIT' s.description = <<-eof xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents ( Excel, Google Spreadsheets, Numbers, LibreOffice) without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine. eof diff --git a/examples/example.rb b/examples/example.rb index 6c8fbd0e..3e409f2d 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -468,6 +468,7 @@ if examples.include? :line_chart chart.valAxis.title = 'Y Axis' end sheet.add_chart(Axlsx::LineChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart| + chart.smooth = true chart.start_at 0, 21 chart.end_at 10, 41 chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "FF0000" diff --git a/examples/merge_cells.rb b/examples/merge_cells.rb new file mode 100644 index 00000000..8b2ead2c --- /dev/null +++ b/examples/merge_cells.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby -w -s +# -*- coding: utf-8 -*- +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +#```ruby +require 'axlsx' +package = Axlsx::Package.new +package.workbook do |workbook| + workbook.add_worksheet name: 'merged_cells' do |sheet| + 4.times do + sheet.add_row %w(a b c d e f g) + end + sheet.merge_cells "A1:A2" + sheet.merge_cells "B1:B2" + end +end +package.serialize 'merged_cells.xlsx' diff --git a/examples/no_grid_with_borders.rb b/examples/no_grid_with_borders.rb new file mode 100644 index 00000000..aed9eb76 --- /dev/null +++ b/examples/no_grid_with_borders.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby -w -s +# -*- coding: utf-8 -*- +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +#```ruby +require 'axlsx' +package = Axlsx::Package.new +package.workbook do |workbook| + workbook.styles do |s| + gridstyle_border = s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" } + workbook.add_worksheet :name => "Custom Borders" do |sheet| + sheet.sheet_view.show_grid_lines = false + sheet.add_row ["with", "grid", "style"], :style => gridstyle_border + sheet.add_row ["no", "border"] + end + end +end +package.serialize 'no_grid_with_borders.xlsx' diff --git a/examples/pivot_test.rb b/examples/pivot_test.rb new file mode 100644 index 00000000..80bdcd84 --- /dev/null +++ b/examples/pivot_test.rb @@ -0,0 +1,63 @@ +class RandomReportGenerator + def date + Date.today.strftime("%m/%d/%Y") + end + def member_id + @i ||= 0 + @i += 1 + end + def name + "John S." + end + def gender + ["Male", "Female"].sample + end + def age + rand(100) + end + def city + ["New York", "Mountain View", "Newark", "Phoenix"].sample + end + def state + ["NY", "CA", "NJ", "AZ"].sample + end + def parenting + "Foo" + end + def student + "Bar" + end + def income + "Bar" + end + def education + "Bar" + end + def answer + ["Yes", "No", "Maybe", "I dont know"].sample + end + def run + package = Axlsx::Package.new + workbook = package.workbook + + workbook.add_worksheet(:name => "Data Sheet") do |sheet| + sheet.add_row [ + "Date", "Member ID", "Name", "Gender", "Age", "City", "State", + "Parenting Status", "Student Status", "Income", "Education", "Answer" + ] + 30.times do + sheet.add_row [date, member_id, name, gender, age, city, state, + parenting, student, income, education, answer] + end + end + + workbook.add_worksheet(:name => "Summary") do |sheet| + pivot_table = Axlsx::PivotTable.new 'A1:B15', "A1:L31", workbook.worksheets[0] + pivot_table.rows = ['Answer'] + pivot_table.data = [{:ref => "Member ID", :subtotal => "count"}] + sheet.pivot_tables << pivot_table + end + + package.serialize("pivot_table.xlsx") + end +end diff --git a/lib/axlsx/drawing/line_chart.rb b/lib/axlsx/drawing/line_chart.rb index 699050dc..8ff32412 100644 --- a/lib/axlsx/drawing/line_chart.rb +++ b/lib/axlsx/drawing/line_chart.rb @@ -39,6 +39,8 @@ module Axlsx # @return [Symbol] attr_reader :grouping + attr_accessor :smooth + # Creates a new line chart object # @param [GraphicFrame] frame The workbook that owns this chart. # @option options [Cell, String] title @@ -83,6 +85,7 @@ module Axlsx @series.each { |ser| ser.to_xml_string(str_inner) } @d_lbls.to_xml_string(str_inner) if @d_lbls yield str_inner if block_given? + str_inner << '<c:smooth val="1"/>' if smooth axes.to_xml_string(str_inner, :ids => true) str_inner << "</c:" << node_name << ">" axes.to_xml_string(str_inner) diff --git a/notes_on_header_footer.md b/notes_on_header_footer.md index c22f31eb..2be4459a 100644 --- a/notes_on_header_footer.md +++ b/notes_on_header_footer.md @@ -42,16 +42,27 @@ in font name it means none specified. Both of font name and font type can be loc ## Workbook info and page numbering &P - code for "current page #" + &N - code for "total pages" + &D - code for "date" + &T - code for "time" + &G - code for "picture as background" + &U - code for "text single underline" + &E - code for "double underline" + &Z - code for "this workbook's file path" + &F - code for "this workbook's file name" + &A - code for "sheet tab name" + &+ - code for add to page #. + &- - code for subtract from page #. &O - code for "outline style" diff --git a/test/drawing/tc_line_chart.rb b/test/drawing/tc_line_chart.rb index 83ebef97..a14f75dc 100644 --- a/test/drawing/tc_line_chart.rb +++ b/test/drawing/tc_line_chart.rb @@ -7,6 +7,7 @@ class TestLineChart < Test::Unit::TestCase ws = @p.workbook.add_worksheet @row = ws.add_row ["one", 1, Time.now] @chart = ws.add_chart Axlsx::LineChart, :title => "fishery" + @chart.smooth = true end def teardown @@ -19,11 +20,11 @@ class TestLineChart < Test::Unit::TestCase assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created") end - def test_grouping - assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } - assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked } - assert(@chart.grouping == :stacked) - end + def test_grouping + assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } + assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked } + assert(@chart.grouping == :stacked) + end def test_to_xml schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) |
