kmadej_fast_excel_fork 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +28 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +70 -0
  7. data/Makefile +14 -0
  8. data/README.md +95 -0
  9. data/Rakefile +24 -0
  10. data/appveyor.yml +25 -0
  11. data/benchmarks/1k_rows.rb +59 -0
  12. data/benchmarks/20k_rows.rb +26 -0
  13. data/benchmarks/init.rb +59 -0
  14. data/benchmarks/memory.rb +49 -0
  15. data/examples/example.rb +42 -0
  16. data/examples/example_align.rb +23 -0
  17. data/examples/example_chart.rb +21 -0
  18. data/examples/example_colors.rb +37 -0
  19. data/examples/example_formula.rb +18 -0
  20. data/examples/example_image.rb +13 -0
  21. data/examples/example_styles.rb +27 -0
  22. data/examples/logo.png +0 -0
  23. data/extconf.rb +0 -0
  24. data/fast_excel.gemspec +20 -0
  25. data/lib/fast_excel.rb +600 -0
  26. data/lib/fast_excel/binding.rb +2819 -0
  27. data/lib/fast_excel/binding/chart.rb +2666 -0
  28. data/lib/fast_excel/binding/format.rb +1177 -0
  29. data/lib/fast_excel/binding/workbook.rb +338 -0
  30. data/lib/fast_excel/binding/worksheet.rb +1555 -0
  31. data/libxlsxwriter/.gitignore +49 -0
  32. data/libxlsxwriter/.indent.pro +125 -0
  33. data/libxlsxwriter/.travis.yml +25 -0
  34. data/libxlsxwriter/CONTRIBUTING.md +226 -0
  35. data/libxlsxwriter/Changes.txt +557 -0
  36. data/libxlsxwriter/LICENSE.txt +89 -0
  37. data/libxlsxwriter/Makefile +156 -0
  38. data/libxlsxwriter/Readme.md +78 -0
  39. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +30 -0
  40. data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +7 -0
  41. data/libxlsxwriter/include/xlsxwriter.h +23 -0
  42. data/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  43. data/libxlsxwriter/include/xlsxwriter/chart.h +3476 -0
  44. data/libxlsxwriter/include/xlsxwriter/common.h +372 -0
  45. data/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  46. data/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  47. data/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  48. data/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  49. data/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  50. data/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  51. data/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  52. data/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  53. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  54. data/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  55. data/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  56. data/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +214 -0
  57. data/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  58. data/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  59. data/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  60. data/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  61. data/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  62. data/libxlsxwriter/include/xlsxwriter/workbook.h +757 -0
  63. data/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  64. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  65. data/libxlsxwriter/lib/.gitignore +0 -0
  66. data/libxlsxwriter/libxlsxwriter.podspec +47 -0
  67. data/libxlsxwriter/src/Makefile +130 -0
  68. data/libxlsxwriter/src/app.c +443 -0
  69. data/libxlsxwriter/src/chart.c +6346 -0
  70. data/libxlsxwriter/src/content_types.c +345 -0
  71. data/libxlsxwriter/src/core.c +293 -0
  72. data/libxlsxwriter/src/custom.c +224 -0
  73. data/libxlsxwriter/src/drawing.c +746 -0
  74. data/libxlsxwriter/src/format.c +729 -0
  75. data/libxlsxwriter/src/hash_table.c +223 -0
  76. data/libxlsxwriter/src/packager.c +948 -0
  77. data/libxlsxwriter/src/relationships.c +245 -0
  78. data/libxlsxwriter/src/shared_strings.c +266 -0
  79. data/libxlsxwriter/src/styles.c +1088 -0
  80. data/libxlsxwriter/src/theme.c +348 -0
  81. data/libxlsxwriter/src/utility.c +515 -0
  82. data/libxlsxwriter/src/workbook.c +1930 -0
  83. data/libxlsxwriter/src/worksheet.c +5022 -0
  84. data/libxlsxwriter/src/xmlwriter.c +355 -0
  85. data/libxlsxwriter/third_party/minizip/Makefile +44 -0
  86. data/libxlsxwriter/third_party/minizip/Makefile.am +45 -0
  87. data/libxlsxwriter/third_party/minizip/Makefile.orig +25 -0
  88. data/libxlsxwriter/third_party/minizip/MiniZip64_Changes.txt +6 -0
  89. data/libxlsxwriter/third_party/minizip/MiniZip64_info.txt +74 -0
  90. data/libxlsxwriter/third_party/minizip/README.txt +5 -0
  91. data/libxlsxwriter/third_party/minizip/configure.ac +32 -0
  92. data/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  93. data/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  94. data/libxlsxwriter/third_party/minizip/ioapi.h +208 -0
  95. data/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  96. data/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  97. data/libxlsxwriter/third_party/minizip/make_vms.com +25 -0
  98. data/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  99. data/libxlsxwriter/third_party/minizip/miniunzip.1 +63 -0
  100. data/libxlsxwriter/third_party/minizip/minizip.1 +46 -0
  101. data/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  102. data/libxlsxwriter/third_party/minizip/minizip.pc.in +12 -0
  103. data/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  104. data/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  105. data/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  106. data/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  107. data/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  108. data/libxlsxwriter/third_party/minizip/zip.h +367 -0
  109. data/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  110. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  111. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  112. data/libxlsxwriter/version.txt +1 -0
  113. data/test/date_test.rb +22 -0
  114. data/test/default_format_test.rb +19 -0
  115. data/test/format_test.rb +171 -0
  116. data/test/test_helper.rb +52 -0
  117. data/test/tmpfile_test.rb +23 -0
  118. data/test/worksheet_test.rb +86 -0
  119. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c036baf1c91ac62746a505b2a05e5911da35172
4
+ data.tar.gz: 7b984910b9ba3a6f8a081fff195665815a4d6810
5
+ SHA512:
6
+ metadata.gz: 7da1e648fc700d7ed47bd41bdfdf0fe11041e0cbc3671208d65afc0a76c43e85137f8de648ea1327905ce2fbd5ca9d2fd5bb5739a107d3644de808f407e32d42
7
+ data.tar.gz: 0184f0ac3e58b9acf1f44a3627bac1e7d1083cc32a211ec7c2ddd9846d3202152847960af57102f9c3bbe230b0a066b1dedc4b1238a9017414289cfaac1d4cf1
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .ruby-version
2
+ try.c
3
+ try.rb
4
+ gen.rb
5
+ gen_ffi.rb
6
+ *.xlsx
7
+ a.out
8
+ .DS_Store
9
+ *.gem
10
+ libxlsxwriter/dev
11
+ libxlsxwriter/docs
12
+ libxlsxwriter/examples
13
+ libxlsxwriter/test
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ ---
2
+ language: ruby
3
+
4
+ matrix:
5
+ include:
6
+ - os: linux
7
+ rvm: 2.1
8
+ - os: osx
9
+ rvm: 2.1
10
+ - os: linux
11
+ rvm: 2.2.7
12
+ - os: osx
13
+ rvm: 2.2.7
14
+ - os: linux
15
+ rvm: 2.3.4
16
+ - os: osx
17
+ rvm: 2.3.4
18
+ - os: linux
19
+ rvm: 2.4.0
20
+ - os: osx
21
+ rvm: 2.4.0
22
+ fast_finish: true
23
+
24
+ script:
25
+ - bundle install
26
+ - make
27
+ - bundle exec rake test
28
+ - bundle exec rake examples
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ #### Version 0.2.1 - 20 jun 2017
2
+
3
+ * Add FastExcel::Formula
4
+
5
+ #### Version 0.2.0 - 24 apr 2017
6
+
7
+ * Add FastExcel.date_num
8
+ * Add feature to use user default font
9
+ * Add benchmarks
10
+
11
+ #### Version 0.1.0 - 24 feb 2017
12
+
13
+ Initial
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'ffi'
4
+ gem 'ffi_gen', require: false
5
+
6
+ gem 'rake'
7
+
8
+ gem 'roo', '2.7.1', git: 'https://github.com/roo-rb/roo.git'
9
+
10
+ gem 'minitest'
11
+ gem 'minitest-reporters'
12
+
13
+ # For benchmakrs
14
+ gem 'axlsx', git: 'https://github.com/randym/axlsx.git'
15
+ gem 'write_xlsx'
16
+ gem 'benchmark-ips'
17
+ gem 'process_memory', git: 'https://github.com/paxa/process_memory', platforms: :ruby
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ GIT
2
+ remote: https://github.com/paxa/process_memory
3
+ revision: 1aa4df28c9a98903301317236104abe591e086fd
4
+ specs:
5
+ process_memory (0.1)
6
+
7
+ GIT
8
+ remote: https://github.com/randym/axlsx.git
9
+ revision: c8ac844572b25fda358cc01d2104720c4c42f450
10
+ specs:
11
+ axlsx (2.1.0.pre)
12
+ htmlentities (~> 4.3.4)
13
+ mimemagic (~> 0.3)
14
+ nokogiri (>= 1.6.6)
15
+ rubyzip (>= 1.2.1)
16
+
17
+ GIT
18
+ remote: https://github.com/roo-rb/roo.git
19
+ revision: 85c2736b0ea1c984391688c5aeb4acf85f225405
20
+ specs:
21
+ roo (2.7.1)
22
+ nokogiri (~> 1)
23
+ rubyzip (>= 1.2.1, < 2.0.0)
24
+
25
+ GEM
26
+ remote: https://rubygems.org/
27
+ specs:
28
+ ansi (1.5.0)
29
+ benchmark-ips (2.7.2)
30
+ builder (3.2.3)
31
+ ffi (1.9.18)
32
+ ffi_gen (1.2.0)
33
+ ffi (~> 1.0)
34
+ htmlentities (4.3.4)
35
+ mimemagic (0.3.2)
36
+ mini_portile2 (2.2.0)
37
+ minitest (5.10.2)
38
+ minitest-reporters (1.1.14)
39
+ ansi
40
+ builder
41
+ minitest (>= 5.0)
42
+ ruby-progressbar
43
+ nokogiri (1.8.0)
44
+ mini_portile2 (~> 2.2.0)
45
+ rake (12.0.0)
46
+ ruby-progressbar (1.8.1)
47
+ rubyzip (1.2.1)
48
+ write_xlsx (0.85.1)
49
+ rubyzip (>= 1.0.0)
50
+ zip-zip
51
+ zip-zip (0.3)
52
+ rubyzip (>= 1.0.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ axlsx!
59
+ benchmark-ips
60
+ ffi
61
+ ffi_gen
62
+ minitest
63
+ minitest-reporters
64
+ process_memory!
65
+ rake
66
+ roo (= 2.7.1)!
67
+ write_xlsx
68
+
69
+ BUNDLED WITH
70
+ 1.15.1
data/Makefile ADDED
@@ -0,0 +1,14 @@
1
+ Q=@
2
+ ifdef V
3
+ Q=
4
+ endif
5
+
6
+ all :
7
+ @echo "Compiling libxlsxwriter ..."
8
+ $(Q)$(MAKE) -C libxlsxwriter
9
+
10
+ clean :
11
+ $(Q)$(MAKE) clean -C libxlsxwriter
12
+
13
+ install :
14
+ @echo "Nothing to install"
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Ultra Fast Excel Writter for Ruby
2
+
3
+ ```ruby
4
+ require 'fast_excel'
5
+
6
+ workbook = FastExcel.open("hello_world_ffi.xlsx", constant_memory: true)
7
+ workbook.default_format.set(
8
+ font_size: 0, # user's default
9
+ font_family: "Arial"
10
+ )
11
+
12
+ worksheet = workbook.add_worksheet("Example Report")
13
+
14
+ bold = workbook.bold_cell_format
15
+ worksheet.set_column(0, 0, FastExcel::DEF_COL_WIDTH, bold)
16
+
17
+ price = workbook.number_format("#,##0.00")
18
+ worksheet.set_column(1, 1, 20, price)
19
+
20
+ date_format = workbook.number_format("[$-409]m/d/yy h:mm AM/PM;@")
21
+ worksheet.set_column(2, 2, 20, date_format)
22
+
23
+ worksheet.write_row(0, ["message", "price", "date"], bold)
24
+
25
+ for i in 1..1000
26
+ worksheet.write_row(i, ["Hello", (rand * 10_000_000).round(2), Time.now])
27
+ end
28
+
29
+ worksheet.write_row(1001, ["Sum", FastExcel::Formula.new("SUM(B2:B1001)")], bold)
30
+
31
+ workbook.close
32
+ ```
33
+
34
+ This repositiry and gem contain sources of [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter)
35
+
36
+ ## Benchmarks
37
+
38
+ 1000 rows:
39
+ ```
40
+ Comparison:
41
+ FastExcel: 31.7 i/s
42
+ Axlsx: 8.0 i/s - 3.98x slower
43
+ write_xlsx: 6.9 i/s - 4.62x slower
44
+ ```
45
+
46
+ 20000 rows:
47
+ ```
48
+ Comparison:
49
+ FastExcel: 1.4 i/s
50
+ Axlsx: 0.4 i/s - 3.46x slower
51
+ write_xlsx: 0.1 i/s - 17.04x slower
52
+ ```
53
+
54
+ Max memory usage, generating 100k rows:
55
+ ```
56
+ FastExcel - 20 MB
57
+ Axlsx - 60 MB
58
+ write_xlsx - 100 MB
59
+ ```
60
+
61
+ ## Install
62
+
63
+ ```ruby
64
+ # Gemfile
65
+ gem 'fast_excel'
66
+ ```
67
+ Or
68
+ ```
69
+ gem install fast_excel
70
+ ```
71
+
72
+ ## API
73
+
74
+ This gem is FFI binding for libxlsxwriter C library with some syntax sugar. All original functions is avaliable, for example:
75
+
76
+ ```ruby
77
+ Libxlsxwriter.worksheet_activate(worksheet) # => will call void worksheet_activate(lxw_worksheet *worksheet)
78
+ # or shorter:
79
+ worksheet.activate
80
+ ```
81
+
82
+ Full libxlsxwriter documentation: [http://libxlsxwriter.github.io/](http://libxlsxwriter.github.io/)
83
+
84
+ Helper Methods:
85
+
86
+ * `FastExcel.open(filename = nil, constant_memory: false, default_format: {})` - open new workbook, if `filename` is nil - it will craete tmp file, `default_format` will be called with `workbook.default_format.set(...)`
87
+ * `FastExcel.date_num(time, offset = nil)` - generate Excel's internal date value, number of days since 1900-Jan-01, works faster then creating `Libxlsxwriter::Datetime` struct. `offset` argument is number hours from UTC, e.g. `3.5`
88
+ * `FastExcel.print_ffi_obj(object)` - print FFI object fields, just for debugging
89
+ * `workbook.bold_cell_format` - shortcut for creating bold format
90
+ * `workbook.number_format(num_format)` - create number or date format, for money usually: `"#,##0.00"`, for date: `"[$-409]m/d/yy h:mm AM/PM;@"`
91
+ * `workbook.read_string` - close workbook, read file to string, delete file (only if tmp file)
92
+ * `workbook.remove_tmp_file` - delete tmp file (only if tmp file)
93
+ * `worksheet.write_row(row_num, array_of_mixed_value, formats = nil)` - write values one by one, detecting type automatically. `formats` can be array, or Format object or nil
94
+ * `format.font_family` - alias for `format.font_name`
95
+ * `workbook.default_format.font_size` - set it to 0 if you want to use default font size (that what user set in Excel settings)
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ desc "Sync github.com:Paxa/libxlsxwriter to ./libxlsxwriter"
2
+ task :sync do
3
+ require 'fileutils'
4
+ FileUtils.rm_rf("./libxlsxwriter")
5
+ system("git clone --depth 10 git@github.com:Paxa/libxlsxwriter.git")
6
+ Dir.chdir("./libxlsxwriter") do
7
+ system("git show --pretty='format:%cd %h' --date=iso --quiet > version.txt")
8
+ FileUtils.rm_rf("./.git")
9
+ end
10
+ end
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new do |test|
15
+ test.test_files = Dir.glob('test/**/*_test.rb')
16
+ end
17
+
18
+ #task :default => :test
19
+
20
+ task :examples do
21
+ Dir.glob('examples/**/*.rb').each do |file|
22
+ require './' + file.sub(/\.rb$/, '')
23
+ end
24
+ end
data/appveyor.yml ADDED
@@ -0,0 +1,25 @@
1
+ install:
2
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
3
+ - SET PATH=C:\MinGW\bin;%PATH%
4
+ - SET RAKEOPT=-rdevkit
5
+ - copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe
6
+ - ruby --version
7
+ - gem --version
8
+ - bundle install
9
+ - make
10
+
11
+ build: off
12
+
13
+ test_script:
14
+ - bundle exec rake test
15
+
16
+ environment:
17
+ matrix:
18
+ - ruby_version: "24"
19
+ - ruby_version: "24-x64"
20
+ - ruby_version: "23"
21
+ - ruby_version: "23-x64"
22
+ - ruby_version: "22"
23
+ - ruby_version: "22-x64"
24
+ - ruby_version: "21"
25
+ - ruby_version: "21-x64"
@@ -0,0 +1,59 @@
1
+ require_relative 'init'
2
+
3
+ HEADERS = ["id", "name", "age", "date"]
4
+
5
+ DATA = []
6
+ 1000.times do |n|
7
+ DATA << [n, "String string #{n}", (n * rand * 10).round, Time.at(n * 1000 + 1492922688)]
8
+ end
9
+
10
+ Benchmark.ips do |x|
11
+ x.config(time: 10, warmup: 2)
12
+
13
+ x.report("FastExcel") do
14
+ workbook = FastExcel.open(constant_memory: true)
15
+ worksheet = workbook.add_worksheet("benchmark")
16
+
17
+ worksheet.write_row(0, HEADERS)
18
+ DATA.each_with_index do |row, i|
19
+ worksheet.write_row(i + 1, row)
20
+ end
21
+ workbook.read_string
22
+ end
23
+
24
+ x.report("Axlsx") do
25
+ filename = "#{Dir.mktmpdir}/axlsx.xlsx"
26
+ Axlsx::Package.new do |package|
27
+ package.use_autowidth = false
28
+ package.workbook.add_worksheet do |sheet|
29
+ sheet.add_row(HEADERS)
30
+ DATA.each do |row|
31
+ sheet.add_row(row)
32
+ end
33
+ end
34
+ package.serialize(filename)
35
+ File.open(filename, 'rb', &:read)
36
+ File.delete(filename)
37
+ end
38
+ end
39
+
40
+ x.report("write_xlsx") do
41
+ filename = "#{Dir.mktmpdir}/write_xlsx.xlsx"
42
+ workbook = WriteXLSX.new(filename)
43
+ worksheet = workbook.add_worksheet
44
+ HEADERS.each_with_index do |value, i|
45
+ worksheet.write(0, i, value)
46
+ end
47
+ DATA.each_with_index do |row, row_num|
48
+ worksheet.write_number(row_num + 1, 0, row[0])
49
+ worksheet.write_string(row_num + 1, 1, row[1])
50
+ worksheet.write_number(row_num + 1, 2, row[2])
51
+ worksheet.write_number(row_num + 1, 3, row[3])
52
+ end
53
+ workbook.close
54
+ File.open(filename, 'rb', &:read)
55
+ File.delete(filename)
56
+ end
57
+
58
+ x.compare!
59
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'init'
2
+
3
+ HEADERS = ["id", "name", "age", "date", "random"]
4
+
5
+ DATA = []
6
+ 20_000.times do |n|
7
+ DATA << [n, "String string #{n}" * 5, (n * rand * 10).round, Time.at(n * 1000 + 1492922688), n * 100]
8
+ end
9
+
10
+ Benchmark.ips do |x|
11
+ x.config(time: 10, warmup: 2)
12
+
13
+ x.report("FastExcel") do
14
+ write_fast_excel_20k
15
+ end
16
+
17
+ x.report("Axlsx") do
18
+ write_axlsx_20k
19
+ end
20
+
21
+ x.report("write_xlsx") do
22
+ write_xlsx_20k
23
+ end
24
+
25
+ x.compare!
26
+ end
@@ -0,0 +1,59 @@
1
+ require 'bundler/setup'
2
+ require 'fileutils'
3
+ require 'tmpdir'
4
+ require_relative '../lib/fast_excel'
5
+
6
+ # gem install axlsx benchmark-ips write_xlsx
7
+
8
+ require "benchmark/ips"
9
+ require 'axlsx'
10
+ require 'write_xlsx'
11
+ require 'process_memory'
12
+
13
+ require_relative 'init'
14
+
15
+ def write_fast_excel_20k
16
+ workbook = FastExcel.open(constant_memory: true)
17
+ worksheet = workbook.add_worksheet("benchmark")
18
+
19
+ worksheet.write_row(0, HEADERS)
20
+ DATA.each_with_index do |row, i|
21
+ worksheet.write_row(i + 1, row)
22
+ end
23
+ workbook.read_string
24
+ end
25
+
26
+ def write_xlsx_20k
27
+ filename = "#{Dir.mktmpdir}/write_xlsx.xlsx"
28
+ workbook = WriteXLSX.new(filename)
29
+ worksheet = workbook.add_worksheet
30
+ HEADERS.each_with_index do |value, i|
31
+ worksheet.write(0, i, value)
32
+ end
33
+ DATA.each_with_index do |row, row_num|
34
+ worksheet.write_number(row_num + 1, 0, row[0])
35
+ worksheet.write_string(row_num + 1, 1, row[1])
36
+ worksheet.write_number(row_num + 1, 2, row[2])
37
+ worksheet.write_number(row_num + 1, 3, row[3])
38
+ worksheet.write_number(row_num + 1, 4, row[4])
39
+ end
40
+ workbook.close
41
+ File.open(filename, 'rb', &:read)
42
+ File.delete(filename)
43
+ end
44
+
45
+ def write_axlsx_20k
46
+ filename = "#{Dir.mktmpdir}/axlsx.xlsx"
47
+ Axlsx::Package.new do |package|
48
+ package.use_autowidth = false
49
+ package.workbook.add_worksheet do |sheet|
50
+ sheet.add_row(HEADERS)
51
+ DATA.each do |row|
52
+ sheet.add_row(row)
53
+ end
54
+ end
55
+ package.serialize(filename)
56
+ File.open(filename, 'rb', &:read)
57
+ File.delete(filename)
58
+ end
59
+ end