This file contains 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 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 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 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 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 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 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
if RUBY_VERSION == "1.8.7" | |
nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\xE2]") | |
else | |
nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\u2028]") | |
end |
This file contains 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
class Array | |
# A more meaningful message when you have an insufficient number of columns | |
# in a row for transposition. | |
MSG_TRANSPOSE_INDEX_ERROR = "Row %s has only %s element(s), but transposition | |
requires %s. Please specify a block to populate missing items or adjust | |
your array to contain an equal number of elements in each row array." | |
# Overrides the default transpose method to allow a block that can be used to return | |
# elements required to populate the transposition. |
This file contains 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 | |
wb = p.workbook | |
wb.add_worksheet(:name => 'defined name') do |sheet| | |
sheet.add_row [1, 2, 17, '=FOOBAR'] | |
wb.add_defined_name("'defined name'!$C1", :local_sheet_id => sheet.index, :name => 'FOOBAR') | |
end | |
p.serialize 'custom_defined_name' |
This file contains 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
# encoding: UTF-8 | |
# | |
require 'nkf' | |
class PhoneticMap | |
def data | |
@data ||= build_data | |
end | |
def index_of(string) |
OlderNewer