merge_excel 0.2.1 → 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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +40 -0
- data/lib/merge_excel/excel.rb +5 -5
- data/lib/merge_excel/settings/parser.rb +2 -3
- data/lib/merge_excel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d9194cae8de5e57f5b2c828ed06b84a8bcd64d
|
4
|
+
data.tar.gz: c23be5c9b741ad107636391285f2b90013040c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 411b29d822d1dea25e569bfa1672f3c788e97562cb67c86a4d08b53635dd13c8a4e8eea954bd136b9a45ea70c26522e0395a5703e5bb89a445bc874c228ee1ac
|
7
|
+
data.tar.gz: 38d08dc4376f337ebf92276229b280c57803650a82379751bd771ff39e3188c61696fa1250fb81f9e8abe6bd8b7ba468526365ba5c4eea43f392924cc3ea080b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,46 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
Given `excel_files_dir` the directory where the Excel files you want to merge are placed and `merged_file_path` the path or filename of the destination Excel file.
|
26
|
+
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'merge_excel'
|
30
|
+
|
31
|
+
me = MergeExcel::Excel.new(excel_files_dir)
|
32
|
+
me.merge merged_file_path
|
33
|
+
```
|
34
|
+
By default the command will merge:
|
35
|
+
- all worksheets
|
36
|
+
- the header line (first row)
|
37
|
+
- all rows until an empty one
|
38
|
+
- all columns
|
39
|
+
|
40
|
+
### Options
|
41
|
+
|
42
|
+
Options allows you to control what to merge.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
options = {
|
46
|
+
selector_pattern: "*.xls",
|
47
|
+
sheets_idxs: [1],
|
48
|
+
data_rows: {
|
49
|
+
1 => {
|
50
|
+
header_row: 0, # or :missing
|
51
|
+
data_starting_row: 1,
|
52
|
+
data_first_column: 0,
|
53
|
+
data_last_column: 5 # omit or :last to get all columns
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
me = MergeExcel::Excel.new(excel_files_dir, options)
|
59
|
+
me.merge merged_file_path
|
60
|
+
```
|
61
|
+
|
62
|
+
In this example will be merged only '.xls' files, of which only the columns from 0 to 5 of the second sheet.
|
63
|
+
|
64
|
+
|
25
65
|
|
26
66
|
|
27
67
|
## Development
|
data/lib/merge_excel/excel.rb
CHANGED
@@ -2,18 +2,18 @@ module MergeExcel
|
|
2
2
|
class Excel
|
3
3
|
attr_reader :files
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@settings = Settings::Parser.new(
|
7
|
-
@files
|
5
|
+
def initialize(input_dir, options={})
|
6
|
+
@settings = Settings::Parser.new(options)
|
7
|
+
@files = Dir.glob(File.join(input_dir, @settings.selector_pattern))
|
8
8
|
end
|
9
9
|
|
10
|
-
def merge
|
10
|
+
def merge(output_file_path)
|
11
11
|
wbook = WBook.new(@settings)
|
12
12
|
@files.each do |i_xls_filepath|
|
13
13
|
puts i_xls_filepath
|
14
14
|
wbook.import_data(i_xls_filepath)
|
15
15
|
end
|
16
|
-
wbook.export
|
16
|
+
wbook.export output_file_path
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module MergeExcel
|
2
2
|
module Settings
|
3
3
|
class Parser
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :selector_pattern, :sheets_idxs, :data_rows, :extra_data_rows
|
5
5
|
def initialize(hash)
|
6
|
-
@
|
7
|
-
@output_file_path = hash.fetch(:output_file_path)
|
6
|
+
@selector_pattern = hash.fetch(:selector_pattern){ "*.{xls,xlsx}" }
|
8
7
|
read_sheets_index hash.fetch(:sheets_idxs){ :all }
|
9
8
|
read_data_rows hash.fetch(:data_rows){ {any: DataRow::DEFAULT_DATA_ROW_CONFIG } }
|
10
9
|
read_extra_data_rows hash.fetch(:extra_data_rows){ {any: ExtraDataRow::DEFAULT_EXTRA_DATA_ROW_CONFIG } }
|
data/lib/merge_excel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merge_excel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iwan Buetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|