simple_combine_xls 0.5.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/lib/simple_combine_xls.rb +6 -0
- data/lib/simple_combine_xls/combine.rb +36 -0
- data/lib/simple_combine_xls/config.rb +11 -0
- data/lib/simple_combine_xls/version.rb +3 -0
- data/lib/simple_combine_xls/xls.rb +62 -0
- data/simple_combine_xls.gemspec +26 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 02711f60772b8801a535012be5e088878af3bb8c71d8b36149d84b079b852a7a
|
4
|
+
data.tar.gz: 7d0801748c18cc579c017eb5ae3d2022f0e1ee855e5ade340c43a37e2c904bbb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0de8e3bd237ad32ab73dec47fa85c0bf4cc4a38b51a95946364a4bad851bad4efe95b195c9a547a5b2126116c9d5f929dced20235200d816c913dbc2e55e0595
|
7
|
+
data.tar.gz: 042f6e1c4a3a904c1620b6d6a4ff01befa7014eec1aec8a73d69ecea9c6e4c7cda3e5d1ded70bd3ef5eca9e03bed2bb774706fb9c50f7f918e17fac186670c10
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_combine_xls (0.5.0)
|
5
|
+
spreadsheet (~> 1.2, >= 1.2.8)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
rake (12.3.3)
|
11
|
+
ruby-ole (1.2.12.2)
|
12
|
+
spreadsheet (1.2.8)
|
13
|
+
ruby-ole
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
rake (~> 12.0)
|
20
|
+
simple_combine_xls!
|
21
|
+
spreadsheet (~> 1.2, >= 1.2.8)
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# SimpleCombineXls
|
2
|
+
|
3
|
+
combine excel cell like drawing
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simple_combine_xls'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install simple_combine_xls
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You must define `variable` or `instance variable` if you want combine excel
|
24
|
+
|
25
|
+
Because their `object_id` is the same
|
26
|
+
|
27
|
+
For example
|
28
|
+
|
29
|
+
```rb
|
30
|
+
city1, city2, city3 = "成都", "南充", "自贡"
|
31
|
+
spec = "特色"
|
32
|
+
# menu1, menu2, menu3 object id is not the same
|
33
|
+
menu1, menu2, menu3 = "菜单", "菜单", "菜单"
|
34
|
+
scenic = "景点"
|
35
|
+
datas = [
|
36
|
+
[spec, spec, spec, spec, spec],
|
37
|
+
[city1, menu1, "串串", scenic, "春熙路"],
|
38
|
+
[city1, menu1, nil, scenic, "黄龙溪"],
|
39
|
+
[city1, menu1, "火锅", scenic, "各种免费景点"],
|
40
|
+
[city2, menu2, "米粉", scenic, "蓝天网吧"],
|
41
|
+
[city2, menu2, "锅盔", scenic, "鼎盛网吧"],
|
42
|
+
[city2, menu2, nil, scenic, "五星网吧"],
|
43
|
+
[city2, menu2, nil, scenic, "各种网吧"],
|
44
|
+
[city3, menu3, "鲜锅兔", scenic, "7天酒店"],
|
45
|
+
[city3, menu3, "冷吃兔", scenic, "汉庭酒店"],
|
46
|
+
[city3, menu3, "各种兔", scenic, nil],
|
47
|
+
[city3, menu3,"富顺豆花", scenic, nil]
|
48
|
+
]
|
49
|
+
simple_combine_xls = SimpleCombineXls.new(datas)
|
50
|
+
simple_combine_xls.drawing
|
51
|
+
# Hand over to spreadsheet when after drawing
|
52
|
+
# You can use spreadsheet do anything
|
53
|
+
# Please see https://github.com/zdavatz/spreadsheet
|
54
|
+
simple_combine_xls.xls.write './asd.xls'
|
55
|
+
```
|
56
|
+
|
57
|
+
Will generate excel like this
|
58
|
+
|
59
|
+
<img src="http://smx.clouddn.com/1616733446268.jpg" />
|
60
|
+
|
61
|
+
## Notice
|
62
|
+
|
63
|
+
- `SimpleCombineXls` will converts all objects to string
|
64
|
+
- `SimpleCombineXls` default placeholder is `" "`
|
65
|
+
|
66
|
+
```rb
|
67
|
+
@str = "test"
|
68
|
+
# This is different for simple_combine_xls
|
69
|
+
# Because arr1.map(&:object_id) != arr2.map(&:object_id)
|
70
|
+
arr1 = [@str, @str, @str]
|
71
|
+
arr2 = ["test", "test", "test"]
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SuMingXuan/simple_combine_xls.
|
78
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class SimpleCombineXls
|
2
|
+
attr_reader :datas, :object_ids, :placeholder
|
3
|
+
attr_accessor :xls
|
4
|
+
def initialize(datas, placeholder: nil)
|
5
|
+
validate_arguments!(datas)
|
6
|
+
@placeholder = placeholder || Config.placeholder
|
7
|
+
@datas = datas
|
8
|
+
@object_ids = extract_object_ids
|
9
|
+
end
|
10
|
+
|
11
|
+
def drawing(type: "xls")
|
12
|
+
case type
|
13
|
+
when "xls" then Xls.new(self).export
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def extract_object_ids
|
20
|
+
datas.map do |row|
|
21
|
+
row.map do |cell|
|
22
|
+
# 保证每个 placeholder 生成的 object_id 不同
|
23
|
+
cell = placeholder.dup if cell.nil? || cell.empty?
|
24
|
+
cell.to_s.object_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_arguments!(datas)
|
30
|
+
begin
|
31
|
+
datas[0][0]
|
32
|
+
rescue
|
33
|
+
raise ArgumentError, "datas must be two dimensional array"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spreadsheet"
|
2
|
+
|
3
|
+
class SimpleCombineXls
|
4
|
+
class Xls
|
5
|
+
attr_reader :combine
|
6
|
+
def initialize(combine)
|
7
|
+
@combine = combine
|
8
|
+
end
|
9
|
+
|
10
|
+
def export
|
11
|
+
combine_go
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def xls
|
17
|
+
@xls ||= Spreadsheet::Workbook.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def sheet
|
21
|
+
@sheet ||= xls.create_worksheet
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_original_xls
|
25
|
+
@combine.datas.each_with_index do |row, index|
|
26
|
+
sheet.row(index).concat row
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def combine_go
|
31
|
+
generate_original_xls
|
32
|
+
combine_go!(sanitize_object_ids)
|
33
|
+
combine.xls = xls
|
34
|
+
end
|
35
|
+
|
36
|
+
def combine_go!(sanitize_object_ids)
|
37
|
+
sanitize_object_ids.each_pair do |_, axis|
|
38
|
+
next unless axis[:x].size > 1
|
39
|
+
|
40
|
+
start_row = axis[:x][0]
|
41
|
+
start_col = axis[:y][0]
|
42
|
+
end_row = axis[:x][-1]
|
43
|
+
end_col = axis[:y][-1]
|
44
|
+
sheet.merge_cells(start_row, start_col, end_row, end_col)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def sanitize_object_ids
|
49
|
+
cell_object_ids = {}
|
50
|
+
@combine.object_ids.each_with_index do |cols, row_index|
|
51
|
+
cols.each_with_index do |cell, col_index|
|
52
|
+
cell_object_ids[cell] ||= {}
|
53
|
+
cell_object_ids[cell][:x] ||= []
|
54
|
+
cell_object_ids[cell][:y] ||= []
|
55
|
+
cell_object_ids[cell][:x] << row_index
|
56
|
+
cell_object_ids[cell][:y] << col_index
|
57
|
+
end
|
58
|
+
end
|
59
|
+
cell_object_ids
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/simple_combine_xls/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "simple_combine_xls"
|
5
|
+
spec.version = SimpleCombineXls::VERSION
|
6
|
+
spec.authors = ["sumingxuan"]
|
7
|
+
spec.email = ["1154621382@qq.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{combine excel cell like drawing}
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = "https://github.com/SuMingXuan/simple_combine_xls"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
spec.add_dependency "spreadsheet", '~> 1.2', '>= 1.2.8'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_combine_xls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sumingxuan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: spreadsheet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.2.8
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.2.8
|
33
|
+
description: combine excel cell like drawing
|
34
|
+
email:
|
35
|
+
- 1154621382@qq.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- lib/simple_combine_xls.rb
|
46
|
+
- lib/simple_combine_xls/combine.rb
|
47
|
+
- lib/simple_combine_xls/config.rb
|
48
|
+
- lib/simple_combine_xls/version.rb
|
49
|
+
- lib/simple_combine_xls/xls.rb
|
50
|
+
- simple_combine_xls.gemspec
|
51
|
+
homepage: https://github.com/SuMingXuan/simple_combine_xls
|
52
|
+
licenses: []
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/SuMingXuan/simple_combine_xls
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.3.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.8
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: combine excel cell like drawing
|
74
|
+
test_files: []
|