excelsed 0.0.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/lib/excelsed.rb +40 -0
- metadata +42 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce79cdddde52bdc40f06d7ae9f9ab5c08b39f834bccb0701b0a2c99fd1de5818
|
4
|
+
data.tar.gz: 27b328409b5d0d0655008514e913095ab8f92180b5596792b37f4de9b4694ec9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16bf7fea436b42c4199dbb59eb1253939d37c8b53d2bade75bdf97576eec97ff86b27c6950d7f4fa66b6d2b7928c5739fe81c521fcec6b5a62628c57e10222c2
|
7
|
+
data.tar.gz: 9e29ae7f9a8480cf4a71c66def826a52ccb7e276ed540a1bfc5e3ed5ffab891494c01971bd09a593d0ff5bdfe4b3dba617a60aa5f5700187a0491d2c70d4fda5
|
data/lib/excelsed.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Excelsed
|
2
|
+
attr_reader :file_path, :scan_mappings, :output_dir, :tmp_dir, :file_name
|
3
|
+
|
4
|
+
def initialize file_path, scan_mappings, output_dir, file_name: 'output'
|
5
|
+
@file_path = file_path
|
6
|
+
@scan_mappings = scan_mappings
|
7
|
+
@output_dir = output_dir
|
8
|
+
@tmp_dir = "#{output_dir}/tmp"
|
9
|
+
@file_name = file_name
|
10
|
+
|
11
|
+
FileUtils.mkdir_p(tmp_dir)
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform
|
15
|
+
perform_unzip
|
16
|
+
sed_mappings
|
17
|
+
export_result
|
18
|
+
|
19
|
+
{file_path: "#{output_dir}/#{file_name}.xlsx"}
|
20
|
+
ensure
|
21
|
+
FileUtils.rm_rf(tmp_dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def perform_unzip
|
27
|
+
system("unzip #{file_path} -d #{tmp_dir}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def sed_mappings
|
31
|
+
scan_mappings.each do |(key, value)|
|
32
|
+
system("sed -i 's/#{key}/#{value}/g' #{tmp_dir}/xl/sharedStrings.xml")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def export_result
|
37
|
+
system("cd #{tmp_dir} && zip -r #{file_name}.zip _rels docProps xl [Content_Types].xml")
|
38
|
+
system("cd #{tmp_dir} && mv #{file_name}.zip ../#{file_name}.xlsx")
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excelsed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- drubyy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Scan and replace text in xlsx file
|
14
|
+
email: thaiduongtran98@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/excelsed.rb
|
20
|
+
homepage: https://rubygems.org/gems/excelsed
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.0.3
|
39
|
+
signing_key:
|
40
|
+
specification_version: 4
|
41
|
+
summary: Scan and replace text in xlsx file
|
42
|
+
test_files: []
|