diff options
| author | Zsolt Kozaroczy <[email protected]> | 2020-09-11 00:36:29 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-09-11 00:36:29 +0200 |
| commit | 282eec44ef01746ee25931fa6cd287ad083fd40b (patch) | |
| tree | 14504bf429ca264812679ca971c1592853d3f762 /examples/pivot_test.rb | |
| parent | 317e8244e4d17c394c1e181f86df3974623fb865 (diff) | |
| download | caxlsx-282eec44ef01746ee25931fa6cd287ad083fd40b.tar.gz caxlsx-282eec44ef01746ee25931fa6cd287ad083fd40b.zip | |
Restructure examples folder (#47)
Split examples into separate markdown files, each containing a description, sample code, and a screenshot of the resulting xlsx document.
The script `generate.rb` is provided to actually generate the example documents by executing the sample code contained in the markdown files.
Diffstat (limited to 'examples/pivot_test.rb')
| -rw-r--r-- | examples/pivot_test.rb | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/examples/pivot_test.rb b/examples/pivot_test.rb deleted file mode 100644 index 80bdcd84..00000000 --- a/examples/pivot_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -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 |
