This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In a controller | |
document = db.Text(template.render('tpl/estimate.xls',template_values),encoding="utf_8") | |
self.response.headers.add_header('Content-disposition', 'attachment; filename="'+seq+'.xls"') | |
self.response.headers.add_header('Content-type', 'application/vnd.ms-excel; filename="'+seq+'.xls"') | |
self.response.headers.add_header('name', seq+'.xls') | |
self.response.out.write(document) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
Axlsx::Package.new do |p| | |
p.workbook do |wb| | |
styles = wb.styles | |
header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center} | |
tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center } | |
ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1} | |
col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center } | |
label = styles.add_style :alignment => { :indent => 1 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -s | |
# -*- coding: utf-8 -*- | |
$:.unshift "#{File.dirname(__FILE__)}/../lib" | |
require 'axlsx' | |
require 'csv' | |
require 'benchmark' | |
row = [] | |
input = (32..126).to_a.pack('U*').chars.to_a | |
20.times { row << input.shuffle.join} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
p = Axlsx::Package.new | |
p.workbook do |wb| | |
# define your regular styles | |
styles = wb.styles | |
title = styles.add_style :sz => 15, :b => true, :u => true | |
default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER | |
header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true | |
money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER | |
percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
data = [ ['oil-bbl',9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.99 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using Tables: | |
#This will add in the sorting filters for you as well as apply default table styling in excel. | |
#LibraOffice does the filters, but not the styling (as does Google docs if I recall correctly.) | |
#```ruby | |
wb.add_worksheet(:name => "Table") do |sheet| | |
sheet.add_row ["Build Matrix"] | |
sheet.add_row ["Build", "Duration", "Finished", "Rvm"] | |
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#```ruby | |
require 'axlsx' | |
p = Axlsx::Package.new | |
wb = p.workbook | |
wb.add_worksheet(:name => "repeated header") do |sheet| | |
sheet.add_row %w(These Column Header Will Render On Every Printed Sheet) | |
200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) } | |
# This is the magic | |
wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = Axlsx::Package.new | |
p.workbook.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 | |
chart.d_lbls.d_lbl_pos = :outEnd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
p = Axlsx::Package.new | |
p.workbook.add_worksheet(:name => "Line Chart") do |sheet| | |
sheet.add_row ['1', '2', '3', '4'] | |
sheet.add_row [1, 2, 3, '=sum(A2:C2)'] | |
sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart| | |
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"] | |
chart.serAxis.tick_lbl_pos = :none |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" | |
require 'axlsx' | |
require 'date' | |
p = Axlsx::Package.new | |
wb = p.workbook | |
wb.styles do |style| | |
# Date/Time Styles | |
# |
OlderNewer