fast_excel 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.gitignore +7 -0
  4. data/.travis.yml +32 -9
  5. data/CHANGELOG.md +36 -1
  6. data/Dockerfile.test +17 -0
  7. data/Gemfile +2 -1
  8. data/Gemfile.lock +33 -24
  9. data/LICENSE +21 -0
  10. data/Makefile +13 -0
  11. data/README.md +177 -40
  12. data/Rakefile +11 -1
  13. data/benchmarks/1k_rows.rb +17 -4
  14. data/benchmarks/20k_rows.rb +4 -0
  15. data/benchmarks/auto_width.rb +37 -0
  16. data/benchmarks/init.rb +14 -2
  17. data/benchmarks/memory.rb +8 -0
  18. data/benchmarks/profiler.rb +27 -0
  19. data/benchmarks/write_value.rb +62 -0
  20. data/examples/example.rb +3 -3
  21. data/examples/example_auto_width.rb +26 -0
  22. data/examples/example_filters.rb +36 -0
  23. data/examples/example_formula.rb +1 -3
  24. data/examples/example_hyperlink.rb +20 -0
  25. data/ext/fast_excel/extconf.rb +3 -0
  26. data/ext/fast_excel/text_width_ext.c +460 -0
  27. data/fast_excel.gemspec +3 -4
  28. data/letters.html +114 -0
  29. data/lib/fast_excel.rb +131 -25
  30. data/lib/fast_excel/binding.rb +33 -21
  31. data/lib/fast_excel/binding/chart.rb +20 -1
  32. data/lib/fast_excel/binding/format.rb +11 -4
  33. data/lib/fast_excel/binding/workbook.rb +10 -2
  34. data/lib/fast_excel/binding/worksheet.rb +44 -27
  35. data/libxlsxwriter/.gitignore +1 -0
  36. data/libxlsxwriter/.indent.pro +8 -0
  37. data/libxlsxwriter/.travis.yml +12 -0
  38. data/libxlsxwriter/CMakeLists.txt +338 -0
  39. data/libxlsxwriter/CONTRIBUTING.md +1 -1
  40. data/libxlsxwriter/Changes.txt +162 -0
  41. data/libxlsxwriter/LICENSE.txt +65 -4
  42. data/libxlsxwriter/Makefile +33 -11
  43. data/libxlsxwriter/Readme.md +3 -1
  44. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +2 -1
  45. data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +2 -2
  46. data/libxlsxwriter/include/xlsxwriter.h +2 -2
  47. data/libxlsxwriter/include/xlsxwriter/app.h +2 -2
  48. data/libxlsxwriter/include/xlsxwriter/chart.h +164 -13
  49. data/libxlsxwriter/include/xlsxwriter/chartsheet.h +544 -0
  50. data/libxlsxwriter/include/xlsxwriter/common.h +35 -6
  51. data/libxlsxwriter/include/xlsxwriter/content_types.h +5 -2
  52. data/libxlsxwriter/include/xlsxwriter/core.h +2 -2
  53. data/libxlsxwriter/include/xlsxwriter/custom.h +2 -2
  54. data/libxlsxwriter/include/xlsxwriter/drawing.h +3 -2
  55. data/libxlsxwriter/include/xlsxwriter/format.h +8 -8
  56. data/libxlsxwriter/include/xlsxwriter/hash_table.h +1 -1
  57. data/libxlsxwriter/include/xlsxwriter/packager.h +18 -8
  58. data/libxlsxwriter/include/xlsxwriter/relationships.h +2 -2
  59. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +5 -3
  60. data/libxlsxwriter/include/xlsxwriter/styles.h +10 -5
  61. data/libxlsxwriter/include/xlsxwriter/theme.h +2 -2
  62. data/libxlsxwriter/include/xlsxwriter/utility.h +35 -5
  63. data/libxlsxwriter/include/xlsxwriter/workbook.h +234 -57
  64. data/libxlsxwriter/include/xlsxwriter/worksheet.h +780 -91
  65. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +4 -2
  66. data/libxlsxwriter/libxlsxwriter.podspec +4 -2
  67. data/libxlsxwriter/src/Makefile +31 -6
  68. data/libxlsxwriter/src/app.c +2 -2
  69. data/libxlsxwriter/src/chart.c +116 -23
  70. data/libxlsxwriter/src/chartsheet.c +508 -0
  71. data/libxlsxwriter/src/content_types.c +12 -4
  72. data/libxlsxwriter/src/core.c +11 -11
  73. data/libxlsxwriter/src/custom.c +3 -3
  74. data/libxlsxwriter/src/drawing.c +114 -17
  75. data/libxlsxwriter/src/format.c +5 -5
  76. data/libxlsxwriter/src/hash_table.c +1 -1
  77. data/libxlsxwriter/src/packager.c +378 -61
  78. data/libxlsxwriter/src/relationships.c +2 -2
  79. data/libxlsxwriter/src/shared_strings.c +18 -4
  80. data/libxlsxwriter/src/styles.c +59 -12
  81. data/libxlsxwriter/src/theme.c +2 -2
  82. data/libxlsxwriter/src/utility.c +93 -6
  83. data/libxlsxwriter/src/workbook.c +379 -61
  84. data/libxlsxwriter/src/worksheet.c +1240 -174
  85. data/libxlsxwriter/src/xmlwriter.c +18 -9
  86. data/libxlsxwriter/third_party/minizip/Makefile +6 -1
  87. data/libxlsxwriter/third_party/minizip/ioapi.c +10 -0
  88. data/libxlsxwriter/third_party/minizip/zip.c +2 -0
  89. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +2 -2
  90. data/libxlsxwriter/version.txt +1 -1
  91. data/test/auto_width_test.rb +19 -0
  92. data/test/date_test.rb +34 -0
  93. data/test/format_test.rb +8 -0
  94. data/test/reopen_test.rb +22 -0
  95. data/test/test_helper.rb +8 -5
  96. data/test/text_width_test.rb +80 -0
  97. data/test/tmpfile_test.rb +1 -0
  98. data/test/validations_test.rb +47 -0
  99. data/test/worksheet_test.rb +44 -1
  100. metadata +33 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f0bf8afa4f1566ae7cc27fe6b7a59e1d9c0dc0d0
4
- data.tar.gz: eeac6d37268bfc90e54a338e098224acd382309d
2
+ SHA256:
3
+ metadata.gz: b7acf199afdfc96f315ac6487ec4c72a25f6624388d2139821ca1a14aaac9a5e
4
+ data.tar.gz: 071322b38f573d7774a26025c1f866203a9e1b0b0bca143fdbedfc81af274fd0
5
5
  SHA512:
6
- metadata.gz: 75345de42e34f5e4db76737ba2c1ad8d8c2fa74fb44653d1d0c5a86137d635aab3c2abb5297ad32fe6a67e4813e6c57dbd50c543ea5a75404a44ada017e45c2b
7
- data.tar.gz: c37550f5d67c501b16e9199f0a8aab489ea760257d2405f3b0ffbabcb41e20625ee80dfbb89bc7dec1ddb0bf93cc65c5e59b89de55f1727dbb5d85ead3a1e049
6
+ metadata.gz: f0f4583c984b84dd9e4960771ab1d094ade8fc271d66e7052b3bb249a870e5fec0302a898652e020cec61d17ceaa2babf73cf84a3a2556c05f83e1b8cf82182b
7
+ data.tar.gz: 162dee5762798ce6ecac84bcc0cc10f38f03f46d3fd4eb490c039dc2e67ede50294f7bfd744be72e58dedacc41c3aad76997a1642ba3e379d8c33d8edca938d0
data/.dockerignore ADDED
@@ -0,0 +1,2 @@
1
+ libxlsxwriter
2
+ .git
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .ruby-version
2
+ .idea/
2
3
  try.c
3
4
  try.rb
4
5
  gen.rb
@@ -7,7 +8,13 @@ gen_ffi.rb
7
8
  a.out
8
9
  .DS_Store
9
10
  *.gem
11
+ *.cmake
12
+ libxlsxwriter/CmakeFiles
13
+ libxlsxwriter/CmakeCache.txt
10
14
  libxlsxwriter/dev
11
15
  libxlsxwriter/docs
12
16
  libxlsxwriter/examples
13
17
  libxlsxwriter/test
18
+ ext/fast_excel/text_width_ext.o
19
+ ext/fast_excel/Makefile
20
+ ext/fast_excel/text_width_ext.bundle
data/.travis.yml CHANGED
@@ -3,26 +3,49 @@ language: ruby
3
3
 
4
4
  matrix:
5
5
  include:
6
+ # - os: linux
7
+ # rvm: 2.2.10
8
+ # - os: osx
9
+ # rvm: 2.2.10
6
10
  - os: linux
7
- rvm: 2.1
8
- - os: osx
9
- rvm: 2.1
11
+ rvm: 2.3.8
10
12
  - os: linux
11
- rvm: 2.2.7
13
+ rvm: 2.4.6
12
14
  - os: osx
13
- rvm: 2.2.7
15
+ rvm: 2.4.6
14
16
  - os: linux
15
- rvm: 2.3.4
17
+ rvm: 2.5.5
16
18
  - os: osx
17
- rvm: 2.3.4
19
+ rvm: 2.5.5
18
20
  - os: linux
19
- rvm: 2.4.0
21
+ rvm: 2.6.3
22
+ env: BUILD_DOCKER=true
23
+ services:
24
+ - docker
20
25
  - os: osx
21
- rvm: 2.4.0
26
+ rvm: 2.6.3
27
+ osx_image: xcode10.2
28
+ before_script:
29
+ - ls -lah /Applications
30
+ - sudo xcode-select -s /Applications/Xcode-10.2.1.app/Contents/Developer
31
+ - clang --version
32
+ - os: linux
33
+ rvm: 2.7.2
34
+ - os: linux
35
+ rvm: 3.0.0-preview2
22
36
  fast_finish: true
37
+ allow_failures:
38
+ - rvm: 3.0.0-preview2
39
+
40
+ before_install:
41
+ - gem install bundler -v 2.2.2
23
42
 
24
43
  script:
25
44
  - bundle install
26
45
  - make
27
46
  - bundle exec rake test
28
47
  - bundle exec rake examples
48
+ - gem build fast_excel.gemspec
49
+ - export GIT_REPO=${TRAVIS_PULL_REQUEST_SLUG:-$TRAVIS_REPO_SLUG}
50
+ - env
51
+ - if [ -n "$BUILD_DOCKER" ]; then docker build . -f Dockerfile.test --build-arg GIT_REPO --build-arg TRAVIS_COMMIT --build-arg TRAVIS_BRANCH ; fi
data/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ #### Version 0.4.0 - 14 feb 2021
2
+
3
+ * Support ruby 3.0
4
+ * Fix for ffi library loading issue on Windows
5
+
6
+ #### Version 0.3.0 - 23 jul 2020
7
+
8
+ * Add support for FastExcel::URL
9
+ * Add support for writing boolean values
10
+ * Add enable_filters!(end_col: X)
11
+ * Allow to open with an empty existing file
12
+ * Add missing enums to chart
13
+ * Don't change sheet name from "" to nil
14
+ * Support build with docker
15
+ * Fix crash when sheet name exceeds maximum length.
16
+ * [BREAKING CHANGE] Rename `worksheet.right_to_left` to `worksheet.set_right_to_left`:
17
+ - now it will work properly when using the `pry-rails` gem, not forcing the document start from right even when this method is not called.
18
+
19
+ #### Version 0.2.6 - 26 jan 2019
20
+
21
+ * Add column auto width (thanks to @duffyjp)
22
+
23
+ #### Version 0.2.5 - 22 jun 2018
24
+
25
+ * Update libxlsxwriter to 0.7.7
26
+
27
+ #### Version 0.2.4 - 13 mar 2018
28
+
29
+ * Update libxlsxwriter to 0.7.6
30
+ * Don’t crash process when duplicated worksheet name
31
+
32
+ #### Version 0.2.3 - 27 oct 2017
33
+
34
+ * Allow Date along with DateTime in write_value (thanks to @noxern)
35
+
1
36
  #### Version 0.2.2 - 20 sep 2017
2
37
 
3
38
  * Nice setters and getters for format.align
@@ -20,4 +55,4 @@
20
55
 
21
56
  #### Version 0.1.0 - 24 feb 2017
22
57
 
23
- Initial
58
+ Initial
data/Dockerfile.test ADDED
@@ -0,0 +1,17 @@
1
+ FROM ruby
2
+
3
+ RUN gem install fast_excel
4
+
5
+ ARG TRAVIS_COMMIT
6
+ ARG TRAVIS_BRANCH
7
+ ARG GIT_REPO
8
+
9
+ RUN echo "source 'https://rubygems.org'" > Gemfile
10
+
11
+ RUN [ -z "$TRAVIS_COMMIT" ] && \
12
+ echo "gem 'fast_excel', git: 'https://github.com/Paxa/fast_excel.git'" >> Gemfile || true
13
+ RUN [ -z "$TRAVIS_COMMIT" ] || \
14
+ echo "gem 'fast_excel', git: 'https://github.com/${GIT_REPO}.git', branch: '$TRAVIS_BRANCH', ref: '$TRAVIS_COMMIT'" >> Gemfile
15
+
16
+ RUN cat Gemfile
17
+ RUN bundle
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem 'ffi_gen', require: false
5
5
 
6
6
  gem 'rake'
7
7
 
8
- gem 'roo', '2.7.1', git: 'https://github.com/roo-rb/roo.git'
8
+ gem 'roo', '2.8.3', git: 'https://github.com/roo-rb/roo.git', tag: 'v2.8.3'
9
9
 
10
10
  gem 'minitest'
11
11
  gem 'minitest-reporters'
@@ -13,5 +13,6 @@ gem 'minitest-reporters'
13
13
  # For benchmakrs
14
14
  gem 'axlsx', git: 'https://github.com/randym/axlsx.git'
15
15
  gem 'write_xlsx'
16
+ gem 'xlsxtream'
16
17
  gem 'benchmark-ips'
17
18
  gem 'process_memory', git: 'https://github.com/paxa/process_memory', platforms: :ruby
data/Gemfile.lock CHANGED
@@ -1,58 +1,66 @@
1
1
  GIT
2
2
  remote: https://github.com/paxa/process_memory
3
- revision: 1aa4df28c9a98903301317236104abe591e086fd
3
+ revision: 282c75336a4a6b92207cd1eaa57f20887b92601e
4
4
  specs:
5
5
  process_memory (0.1)
6
6
 
7
7
  GIT
8
8
  remote: https://github.com/randym/axlsx.git
9
- revision: c8ac844572b25fda358cc01d2104720c4c42f450
9
+ revision: 8e7b4b3b7259103452c191f73ce0bf64f66033fe
10
10
  specs:
11
- axlsx (2.1.0.pre)
12
- htmlentities (~> 4.3.4)
11
+ axlsx (3.0.0.pre)
12
+ htmlentities (~> 4.3, >= 4.3.4)
13
13
  mimemagic (~> 0.3)
14
- nokogiri (>= 1.6.6)
15
- rubyzip (>= 1.2.1)
14
+ nokogiri (~> 1.8, >= 1.8.2)
15
+ rubyzip (~> 1.2, >= 1.2.1)
16
16
 
17
17
  GIT
18
18
  remote: https://github.com/roo-rb/roo.git
19
- revision: 85c2736b0ea1c984391688c5aeb4acf85f225405
19
+ revision: d416f1520c50bbab160ca2ed9a49498fcc3edf50
20
+ tag: v2.8.3
20
21
  specs:
21
- roo (2.7.1)
22
+ roo (2.8.3)
22
23
  nokogiri (~> 1)
23
- rubyzip (>= 1.2.1, < 2.0.0)
24
+ rubyzip (>= 1.3.0, < 3.0.0)
24
25
 
25
26
  GEM
26
27
  remote: https://rubygems.org/
27
28
  specs:
28
29
  ansi (1.5.0)
29
- benchmark-ips (2.7.2)
30
- builder (3.2.3)
31
- ffi (1.9.18)
30
+ benchmark-ips (2.8.4)
31
+ builder (3.2.4)
32
+ ffi (1.14.2)
32
33
  ffi_gen (1.2.0)
33
34
  ffi (~> 1.0)
34
35
  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)
36
+ mimemagic (0.3.5)
37
+ minitest (5.14.3)
38
+ minitest-reporters (1.4.3)
39
39
  ansi
40
40
  builder
41
41
  minitest (>= 5.0)
42
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)
43
+ nokogiri (1.11.1-x86_64-darwin)
44
+ racc (~> 1.4)
45
+ nokogiri (1.11.1-x86_64-linux)
46
+ racc (~> 1.4)
47
+ racc (1.5.2)
48
+ rake (13.0.3)
49
+ ruby-progressbar (1.11.0)
50
+ rubyzip (1.3.0)
51
+ write_xlsx (1.04.0)
49
52
  rubyzip (>= 1.0.0)
50
53
  zip-zip
54
+ xlsxtream (2.4.0)
55
+ zip_tricks (>= 4.5, < 6)
51
56
  zip-zip (0.3)
52
57
  rubyzip (>= 1.0.0)
58
+ zip_tricks (5.5.0)
53
59
 
54
60
  PLATFORMS
55
61
  ruby
62
+ x86_64-darwin-19
63
+ x86_64-linux
56
64
 
57
65
  DEPENDENCIES
58
66
  axlsx!
@@ -63,8 +71,9 @@ DEPENDENCIES
63
71
  minitest-reporters
64
72
  process_memory!
65
73
  rake
66
- roo (= 2.7.1)!
74
+ roo (= 2.8.3)!
67
75
  write_xlsx
76
+ xlsxtream
68
77
 
69
78
  BUNDLED WITH
70
- 1.15.1
79
+ 2.2.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Pavel Evstigneev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/Makefile CHANGED
@@ -3,9 +3,22 @@ ifdef V
3
3
  Q=
4
4
  endif
5
5
 
6
+ # with xcode better to use cmake
7
+ UNAME_S := $(shell uname -s)
8
+ ifeq ($(UNAME_S),"Darwin")
9
+ USE_CMAKE := $(shell command -v cmake 2> /dev/null)
10
+ endif
11
+
6
12
  all :
13
+ # @echo "Compiling ext/text_width ..."
14
+ # rake compile
7
15
  @echo "Compiling libxlsxwriter ..."
16
+ ifdef USE_CMAKE
17
+ @echo "run cmake libxlsxwriter ..."
18
+ cmake libxlsxwriter
19
+ else
8
20
  $(Q)$(MAKE) -C libxlsxwriter
21
+ endif
9
22
 
10
23
  clean :
11
24
  $(Q)$(MAKE) clean -C libxlsxwriter
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # Ultra Fast Excel Writter for Ruby
1
+ # Ultra Fast Excel Writer for Ruby
2
2
 
3
3
  ```ruby
4
4
  require 'fast_excel'
5
5
 
6
- workbook = FastExcel.open("hello_world_ffi.xlsx", constant_memory: true)
6
+ workbook = FastExcel.open("hello_world.xlsx", constant_memory: true)
7
7
  workbook.default_format.set(
8
8
  font_size: 0, # user's default
9
9
  font_family: "Arial"
@@ -11,7 +11,7 @@ workbook.default_format.set(
11
11
 
12
12
  worksheet = workbook.add_worksheet("Example Report")
13
13
 
14
- bold = workbook.bold_cell_format
14
+ bold = workbook.bold_format
15
15
  worksheet.set_column(0, 0, FastExcel::DEF_COL_WIDTH, bold)
16
16
 
17
17
  price = workbook.number_format("#,##0.00")
@@ -20,56 +20,179 @@ worksheet.set_column(1, 1, 20, price)
20
20
  date_format = workbook.number_format("[$-409]m/d/yy h:mm AM/PM;@")
21
21
  worksheet.set_column(2, 2, 20, date_format)
22
22
 
23
- worksheet.write_row(0, ["message", "price", "date"], bold)
23
+ worksheet.append_row(["message", "price", "date"], bold)
24
24
 
25
25
  for i in 1..1000
26
- worksheet.write_row(i, ["Hello", (rand * 10_000_000).round(2), Time.now])
26
+ worksheet.append_row(["Hello", (rand * 10_000_000).round(2), Time.now])
27
27
  end
28
28
 
29
- worksheet.write_row(1001, ["Sum", FastExcel::Formula.new("SUM(B2:B1001)")], bold)
29
+ worksheet.append_row(["Sum", FastExcel::Formula.new("SUM(B2:B1001)")], bold)
30
30
 
31
31
  workbook.close
32
32
  ```
33
33
 
34
- This repositiry and gem contain sources of [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter)
34
+ See [more examples](https://github.com/Paxa/fast_excel/tree/master/examples)
35
35
 
36
- ## Benchmarks
36
+ This repository and gem contain sources of [libxlsxwriter](https://github.com/jmcnamara/libxlsxwriter)
37
37
 
38
- 1000 rows:
38
+ ## Install
39
+
40
+ ```ruby
41
+ # Gemfile
42
+ gem 'fast_excel'
39
43
  ```
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
+ Or
45
+ ```
46
+ gem install fast_excel
44
47
  ```
45
48
 
46
- 20000 rows:
49
+
50
+
51
+ ### Create Document
52
+ ```ruby
53
+ workbook = FastExcel.open # creates tmp file
54
+ # ...
55
+ send_data(workbook.read_string, filename: "table.xlsx") # read tmp file and delete it
47
56
  ```
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
57
+
58
+ Also can use `workbook.remove_tmp_file` to delete tmp file manually
59
+
60
+
61
+ **Constant memory mode**: saves each row to disk, good for really big files but can not change previous lines that already saved
62
+ ```ruby
63
+ workbook = FastExcel.open(constant_memory: true)
52
64
  ```
53
65
 
54
- Max memory usage, generating 100k rows:
66
+ **Save to file**
67
+ ```ruby
68
+ workbook = FastExcel.open("my_dinner.xlsx")
55
69
  ```
56
- FastExcel - 20 MB
57
- Axlsx - 60 MB
58
- write_xlsx - 100 MB
70
+
71
+ ### Write Data
72
+ FastExcel will automatically detect data type and one of `write_number` or `write_datetime` or `write_formula` or `write_string` or `write_url`
73
+ ```ruby
74
+ workbook = FastExcel.open
75
+ worksheet = workbook.add_worksheet
76
+
77
+ # write specific type value value
78
+ worksheet.write_number(row = 0, col = 5, 1_234_567, format = nil)
79
+
80
+ # write value with type detection
81
+ worksheet.write_value(row = 0, col = 5, 1_234_567, format = nil)
82
+
83
+ # write row of values. format argument can be format object or array of format objects
84
+ worksheet.write_row(row = 1, ["strong", 123_456, Time.now], format = nil)
85
+
86
+ # write row to the bottom
87
+ worksheet.append_row(["strong", 123_456, Time.now], )
88
+
89
+ # shortcut for append_row()
90
+ worksheet << ["strong", 123_456, Time.now]
59
91
  ```
60
92
 
61
- ## Install
93
+ **Saving dates**: excel store dates as number of days since 1st January 1900, and FastExcel will make it for you.
62
94
 
95
+ To make saving of dates slightly faster can use `FastExcel.date_num` helper:
63
96
  ```ruby
64
- # Gemfile
65
- gem 'fast_excel'
97
+ date_format = workbook.number_format("[$-409]m/d/yy hh:mm;@")
98
+ worksheet.write_number(0, 0, FastExcel.date_num(Time.now, Time.zone.utc_offset), date_format)
66
99
  ```
67
- Or
100
+
101
+ **Formulas**: special type of value in excel
102
+ ```ruby
103
+ worksheet << [1, 2, 3, 4]
104
+ worksheet << [FastExcel::Formula.new("SUM(A1:D1)")] # A2 will be shown as 10
68
105
  ```
69
- gem install fast_excel
106
+
107
+ **URL**: Link to website or something else
108
+ ```ruby
109
+ url_format = workbook.add_format(underline: :underline_single, font_color: :blue) # format is optional
110
+ worksheet.append_row([
111
+ FastExcel::URL.new("https://github.com/Paxa/fast_excel"),
112
+ FastExcel::URL.new("postgres://localhost")
113
+ ], url_format)
114
+ # or
115
+ worksheet.write_url(0, 2, "https://github.com/Paxa/fast_excel", url_format)
116
+ ```
117
+
118
+
119
+ ### Data Formatting
120
+ ```ruby
121
+ format = worksheet.add_format(
122
+ bold: true,
123
+ italic: true,
124
+ font_outline: true,
125
+ font_shadow: true,
126
+ text_wrap: true,
127
+ font_strikeout: true,
128
+ shrink: true,
129
+ text_justlast: true,
130
+ font_size: 13, # default is 11, use 0 for user's default
131
+ font_name: "Arial", # default is Calibri, also accessible via font_family
132
+ font_color: :orange, # can use RGB hex as "#FF0000" or 0x00FF00 or color name as symbol or string
133
+ font_script: :font_subscript,
134
+ rotation: 10,
135
+ underline: :underline_single, # or :underline_double or :underline_single_accounting or :underline_double_accounting
136
+ indent: 1,
137
+ # border styles
138
+ border: :border_thin,
139
+ left: :medium,
140
+ top: :dashed,
141
+ right: :double,
142
+ bottom: :hair,
143
+ bottom_color: :alice_blue,
144
+ top_color: "#11ABCD",
145
+ # Align
146
+ align: {h: :align_center, v: :align_vertical_center},
147
+ num_format: "#,##0.00"
148
+ )
70
149
  ```
71
150
 
72
- ## API
151
+ **Shortcuts**:
152
+ ```ruby
153
+ workbook.bold_format # bold text
154
+ workbook.number_format("[$-409]m/d/yy h:mm AM/PM;@") # format for date
155
+ ```
156
+
157
+ ### Set Column Width
158
+
159
+ ```ruby
160
+ worksheet.set_column(start_col, end_col, width = nil, format = nil)
161
+ # or
162
+ worksheet.set_column_width(col, width = 60)
163
+ # or
164
+ worksheet.set_columns_width(start_col, end_col, width = 60)
165
+ ```
166
+
167
+ ### Set Row Height
168
+ ```ruby
169
+ worksheet.set_row(row_num = 0, height = 30, format = nil)
170
+ ```
171
+
172
+ ### Column Auto Width
173
+
174
+ Column authwidth only works for string values, because numbers may have custom formatting
175
+
176
+ Enabling column auto widths will slow down writing string values for about 15-25%
177
+
178
+ ```ruby
179
+ require 'fast_excel'
180
+
181
+ workbook = FastExcel.open(constant_memory: true)
182
+
183
+ worksheet = workbook.add_worksheet
184
+ worksheet.auto_width = true
185
+
186
+ worksheet.append_row(["some text", "some longer text for example"])
187
+
188
+ content = workbook.read_string
189
+ File.open('./some_file.xlsx', 'wb') {|f| f.write(content) }
190
+ ```
191
+
192
+ ![fast_excel_auto_width](https://user-images.githubusercontent.com/26019/51788441-ba981300-21b0-11e9-9611-54dda78effcd.png)
193
+
194
+
195
+ ### API
73
196
 
74
197
  This gem is FFI binding for libxlsxwriter C library with some syntax sugar. All original functions is avaliable, for example:
75
198
 
@@ -81,15 +204,29 @@ worksheet.activate
81
204
 
82
205
  Full libxlsxwriter documentation: [http://libxlsxwriter.github.io/](http://libxlsxwriter.github.io/)
83
206
 
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)
207
+ Generated rdoc: [rubydoc.info/github/Paxa/fast_excel](https://www.rubydoc.info/github/Paxa/fast_excel)
208
+
209
+ ## Benchmarks
210
+
211
+ 1000 rows:
212
+ ```
213
+ Comparison:
214
+ FastExcel: 31.7 i/s
215
+ Axlsx: 8.0 i/s - 3.98x slower
216
+ write_xlsx: 6.9 i/s - 4.62x slower
217
+ ```
218
+
219
+ 20000 rows:
220
+ ```
221
+ Comparison:
222
+ FastExcel: 1.4 i/s
223
+ Axlsx: 0.4 i/s - 3.46x slower
224
+ write_xlsx: 0.1 i/s - 17.04x slower
225
+ ```
226
+
227
+ Max memory usage, generating 100k rows:
228
+ ```
229
+ FastExcel - 20 MB
230
+ Axlsx - 60 MB
231
+ write_xlsx - 100 MB
232
+ ```