summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-18 17:25:55 +0900
committerRandy Morgan <[email protected]>2012-07-18 17:25:55 +0900
commita09f09952359dbadacb9f649d89fa7111af23bee (patch)
tree2643288f04aa16d0f2b6d2ce6f225db236d2b5c3
parent51ec0287e61e4c65e6312d041869ccd9a9538c84 (diff)
downloadcaxlsx-a09f09952359dbadacb9f649d89fa7111af23bee.tar.gz
caxlsx-a09f09952359dbadacb9f649d89fa7111af23bee.zip
dynamic docs… hmmm
-rw-r--r--examples/basic_charts.rb4
-rw-r--r--lib/axlsx/drawing/d_lbls.rb26
-rw-r--r--rubima.md74
3 files changed, 98 insertions, 6 deletions
diff --git a/examples/basic_charts.rb b/examples/basic_charts.rb
index 2d93bb6e..ab5cf522 100644
--- a/examples/basic_charts.rb
+++ b/examples/basic_charts.rb
@@ -9,10 +9,10 @@ wb.add_worksheet(:name => "Pie Chart") do |sheet|
sheet.add_row [1, 2, 3, 4]
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=> 'dark corner here') do |chart|
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
- chart.d_lbls.show_cat_name = true
+ chart.d_lbls.show_val = true
chart.d_lbls.show_percent = true
chart.d_lbls.d_lbl_pos = :outEnd
- chard.d_lbls.show_leader_lines = true
+ chart.d_lbls.show_leader_lines = true
end
end
diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb
index b1c010f1..6682bd07 100644
--- a/lib/axlsx/drawing/d_lbls.rb
+++ b/lib/axlsx/drawing/d_lbls.rb
@@ -1,5 +1,9 @@
module Axlsx
- # <c:dLbls>
+ # There are more elements in the dLbls spec that allow for
+ # customizations and formatting. For now, I am just implementing the
+ # basics.
+ #
+ #<c:dLbls>
#<c:dLblPos val="outEnd"/>
#<c:showLegendKey val="0"/>
#<c:showVal val="0"/>
@@ -12,6 +16,9 @@ module Axlsx
#The DLbls class manages serialization of data labels
class DLbls
+
+ # These attributes are all boolean so I'm doing a bit of a hand
+ # waving magic show to set up the attriubte accessors
BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
# creates a new DLbls object
@@ -24,12 +31,17 @@ module Axlsx
end
+ # Initialize all the values to false as Excel requires them to
+ # explicitly be disabled or all will show.
def initialize_defaults
BOOLEAN_ATTRIBUTES.each do |attr|
self.send("#{attr}=", false)
end
end
+ # The position of the data labels in the chart
+ # @see d_lbl_pos= for a list of allowed values
+ # @return [Symbol]
attr_reader :d_lbl_pos
# @see DLbls#d_lbl_pos
@@ -43,13 +55,19 @@ module Axlsx
@d_lbl_pos = label_position
end
+ # Dynamically create accessors for boolean attriubtes
BOOLEAN_ATTRIBUTES.each do |attr|
class_eval %{
+ # The #{attr} attribute reader
+ # @return [Boolean]
attr_reader :#{attr}
- def #{attr}=(v)
- Axlsx::validate_boolean(v)
- @#{attr} = v
+ # The #{attr} writer
+ # @param [Boolean] value The value to assign to #{attr}
+ # @return [Boolean]
+ def #{attr}=(value)
+ Axlsx::validate_boolean(value)
+ @#{attr} = value
end
}
end
diff --git a/rubima.md b/rubima.md
new file mode 100644
index 00000000..c28850fe
--- /dev/null
+++ b/rubima.md
@@ -0,0 +1,74 @@
+Axlsx – The end of CSV as an excuse for client reporting.
+
+One of the things that keeps popping up for ruby and ruby on rails application developers is client reporting.
+We have tools for creating beautiful screen based reports that make the end user say “WOW”, we can even -
+with the help of a great designer - produce a well formatted PDF. But when it comes to data, we are still
+using CSV, a technology from the 1960's
+
+That has changed. There is a new gem, released in November of last year and still under active development
+that brings more to ruby and ruby on rails than was ever possible before for client reporting.
+
+The gem is axlsx (http://rubygems.org/gems/axlsx)
+
+Let's take a look at some of the things that it can do for you.
+
+1. The Basics
+The basics of generating and serializing xlsx data are dead simple.
+
+1. Create a package
+2. Setup your styles
+3. add a worksheet to the workbook
+3. add your data, charts, images, conditional formatting, data
+ validations, page setup, print options, and password locking,
+comments, cell merges and panes.
+4. serialize
+
+The code below illustrates a trivial example a few of these items
+
+'''ruby
+require 'axlsx'
+
+package = Axlsx::Package.new
+styles = package.workbook.styles
+
+header = styles.add_style :bg_color => '00', :fg_color => 'FF', :sz => 16, :alignment => { :horizontal => :center }
+
+quarter_label = styles.add_style :bg_color => 'FFDFDEDF', :alignment => { :indent => 1 }, :sz => 14
+
+money = styles.add_style :num_fmt => 5, :zd => 14
+
+package.workbook.add_worksheet do |worksheet|
+ worksheet.add_row ['Revenue by Quarter'], :style => header
+ worksheet.merge_cells 'A1:I1'
+ worksheet.add_row
+ data_row_style = [nil, quarter_label, money]
+
+ worksheet.add_row [nil, 'Q1', 35221124], :style => data_row_style
+ worksheet.add_row [nil, 'Q2', 56742113], :style => data_row_style
+ worksheet.add_row [nil, 'Q3', 71165443], :style => data_row_style
+ worksheet.add_row [nil, 'Q4', 98761111], :style => data_row_style
+
+ worksheet.add_chart(Axlsx::Bar3DChart, :bar_dir => :col) do |chart|
+ chart.start_at 4, 2
+ chart.end_at 9, 15
+ chart.title = worksheet['A1']
+ chart.add_series :data => worksheet['C3:C6'], :labels => worksheet['B3:B6']
+ end
+end
+package.serialize 'the_better_basics.xlsx'
+
+If you are using rails, there is a sister gem acts_as_xlsx (http://rubygems.org/gems/axlsx)
+That is going to make you smile as well.
+
+Have a look at these two blog posts for a quick write up of how easy it
+is to use.
+
+http://axlsx.blogspot.jp/2011/12/using-actsasxlsx-to-generate-excel-data.html
+http://axlsx.blogspot.jp/2011/12/axlsx-making-excel-reports-with-ruby-on.html
+
+
+
+
+
+
+