ld 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +80 -41
- data/lib/ld/excel/excel.rb +19 -26
- data/lib/ld/excel/sheet.rb +117 -210
- data/lib/ld/file/file.rb +9 -0
- data/lib/ld/project/project.rb +3 -2
- data/lib/ld/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59674cf5f131112be70e95b3b57c2fce00762ab7
|
4
|
+
data.tar.gz: 251914cdc6f67afa5361fd32854cfc969a8c7166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b54d6f6e9eaac2a4dfd773c54601e1b44ccfbf37a9e4ae0813cb647b9ad14b31dff47fc4489ce6301c8272f833eaf432e71413dba30223d54cf9bfbb6dd1742b
|
7
|
+
data.tar.gz: 5d0b4a91596ad7a254b32110b9a5995d4099353b73df84a012f3bbbeb6c30fe9a9b6209d791c7bac1d21c798f99ac222f0d4297ea9875f776823aa2ed22fdd42
|
data/README.md
CHANGED
@@ -8,17 +8,16 @@ Basically has the following Class.
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
module Ld
|
11
|
+
class File
|
12
|
+
end
|
13
|
+
class Excel
|
14
|
+
end
|
15
|
+
class Project
|
16
|
+
end
|
17
|
+
class Print
|
18
|
+
end
|
11
19
|
end
|
12
20
|
```
|
13
|
-
## Introduction to the
|
14
|
-
|
15
|
-
设计这个gem,我希望可以帮助大家在开发简单rails应用时,可以帮助大家完成50%以上的简单而重复的工作
|
16
|
-
我会提供一些类与方法,在console中使用,调用它们会生成项目结构xls文件,生成的这个xls文件中的数据,类似于一个小型文件数据库
|
17
|
-
然后我们可以以此为基础,查询项目中的一些信息.我想这样会有助于我们快速理解一个项目的基本结构,与重要文件在哪
|
18
|
-
也可以在修复bug时对bug相关文件与方法,起到快速定位的作用
|
19
|
-
这是我设计本gem的初衷,未来应该会持续更新这个gem,让它变得更加强大与方便
|
20
|
-
最终的目的是,希望这个gem可以起到快速搭建简单rails应用的作用,提升工作效率,节省时间
|
21
|
-
比如我们可以集成一些常用的模块到这个gem中,在搭建项目时只需要执行一条简单的命令就可以创建
|
22
21
|
|
23
22
|
## Installation
|
24
23
|
|
@@ -38,47 +37,87 @@ Or install it yourself as:
|
|
38
37
|
|
39
38
|
## Usage
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
$ rails c
|
44
|
-
|
45
|
-
Then, can do this:
|
46
|
-
|
40
|
+
1. Ld::Excel
|
47
41
|
```ruby
|
48
|
-
#
|
49
|
-
Ld::
|
50
|
-
|
51
|
-
|
52
|
-
Ld::Excel.open('project.xls').read('models?a1:j100-f,h,i')
|
53
|
-
Ld::Excel.open('project.xls').read('tables?a1:i300')
|
54
|
-
|
55
|
-
# Create xls, Need to change the file path to your own, and then run
|
56
|
-
Ld::Excel.create :file_path =>'excel_test.xls' do |excel|
|
57
|
-
excel.write_sheet 'sheet1' do |sheet|
|
58
|
-
sheet.set_format({color: :red, font_size: 11, font: '宋体'})
|
59
|
-
sheet.set_headings ['title1','title2','title3']
|
42
|
+
# write excel
|
43
|
+
Ld::Excel.create :file_path => 'config/excel_test.xls' do |excel|
|
44
|
+
excel.write_sheet 'abc' do |sheet|
|
45
|
+
sheet.set_format({color: :red, font_size: 20, font: '微软雅黑'})
|
60
46
|
sheet.set_point 'a1'
|
61
|
-
sheet.
|
62
|
-
|
63
|
-
[1,2,3,4],
|
64
|
-
[
|
65
|
-
[
|
66
|
-
[
|
67
|
-
]
|
47
|
+
sheet.set_headings ['A','B','C','D']
|
48
|
+
sheet.set_rows([
|
49
|
+
['1','2','3','4'],
|
50
|
+
['2','3','4','5'],
|
51
|
+
['3','4','5','6'],
|
52
|
+
['4','5','6','7']
|
53
|
+
])
|
68
54
|
end
|
69
55
|
end
|
70
|
-
Ld::Excel.open('excel_test.xls').read('sheet1?a1:g6')
|
71
56
|
|
72
|
-
#
|
73
|
-
Ld::
|
57
|
+
# read excel
|
58
|
+
excel = Ld::Excel.open('config/excel_test.xls')
|
59
|
+
excel.read('abc?a1:b5')
|
60
|
+
excel.read({sheet: 'abc', scope:'a1:b5'})
|
61
|
+
excel.read({sheet: 'abc', scope:'a1:b5', exclude:'3'})
|
62
|
+
excel.read({sheet: 'abc', scope:'a1:b5', exclude:'B'})
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
2. Ld::Project
|
67
|
+
```ruby
|
68
|
+
# Check the project details
|
69
|
+
project = Ld::Project.new(Rails.root.to_s)
|
70
|
+
|
71
|
+
# create excel to 'config/project_details.xls'
|
72
|
+
|
73
|
+
# Check model infos
|
74
|
+
project.to_xls('config/project_details.xls')
|
75
|
+
project.print :user, :fields
|
76
|
+
project.print :user, :relations
|
77
|
+
project.print :user, :routes
|
78
|
+
project.print :user, :controllers
|
79
|
+
project.print :user, :views
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
3. Ld::File
|
85
|
+
```ruby
|
86
|
+
# read file all lines
|
87
|
+
file = Ld::File.open('config/application.rb')
|
88
|
+
lines = file.lines
|
89
|
+
|
90
|
+
# read dir
|
91
|
+
dir = Ld::File.open('app/models')
|
92
|
+
files = dir.children
|
93
|
+
|
94
|
+
# search dir file by file name
|
95
|
+
files = dir.search_files(/.rb$/)
|
96
|
+
|
97
|
+
# Ld::File API
|
98
|
+
Ld::File.open path
|
99
|
+
Ld::File.new path
|
100
|
+
file.children
|
101
|
+
file.brothers
|
102
|
+
file.father
|
103
|
+
file.lines
|
104
|
+
file.search_files(//)
|
105
|
+
file.search_dirs(//)
|
106
|
+
file.name
|
107
|
+
file.path
|
108
|
+
file.type # 0=file, 1=dir
|
109
|
+
```
|
74
110
|
|
75
|
-
# Read dir or file
|
76
|
-
Ld::File.new('Gemfile').lines.each{|l| puts l}
|
77
|
-
Ld::File.new('app').models.children.each{|f| puts f.name}
|
78
|
-
Ld::File.new('app').views.search_files(/.html/).each{|f| puts "#{f.father.name} : #{f.name}"}
|
79
111
|
|
112
|
+
4. Ld::Print
|
113
|
+
```ruby
|
114
|
+
users = User.first(10)
|
115
|
+
Ld::Print.p users, 'id ,name, created_at'
|
80
116
|
```
|
81
117
|
|
118
|
+
|
119
|
+
|
120
|
+
|
82
121
|
## Development
|
83
122
|
|
84
123
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/ld/excel/excel.rb
CHANGED
@@ -4,65 +4,58 @@ Spreadsheet.client_encoding = 'UTF-8'
|
|
4
4
|
class Ld::Excel
|
5
5
|
attr_accessor :excel, :path
|
6
6
|
|
7
|
-
# 构造函数,如果未传path则是创建一个新的excel, 如果传了path,则打开这个excel,不过打开前会验证后缀与是否存在
|
8
7
|
def initialize path = nil
|
9
8
|
if path
|
10
9
|
if path.match(/.xls$/)
|
11
10
|
if File::exist? path
|
12
11
|
@excel = Spreadsheet.open path
|
13
12
|
@path = path
|
14
|
-
puts "打开文件: #{path}"
|
15
13
|
else
|
16
|
-
raise "
|
14
|
+
raise "File does not exist: #{path}"
|
17
15
|
end
|
18
16
|
else
|
19
|
-
raise "
|
17
|
+
raise "Can only read .xls!"
|
20
18
|
end
|
21
19
|
else
|
22
20
|
@excel = Spreadsheet::Workbook.new
|
23
|
-
puts "创建新的Excel实例"
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
|
-
# 打开一个excel
|
28
24
|
def self.open path
|
29
25
|
self.new path
|
30
26
|
end
|
31
27
|
|
32
|
-
# 获取一页
|
33
28
|
def open_sheet name
|
34
29
|
Ld::Sheet.open @excel, name
|
35
30
|
end
|
36
31
|
|
37
|
-
# 刷新 重读一次
|
38
32
|
def flush
|
39
33
|
@excel = Ld::Excel.open @path
|
40
34
|
end
|
41
35
|
|
42
|
-
#
|
43
|
-
def read
|
44
|
-
raise "缺少?, 需要在'?'左边指定sheet的名称" if !address_path_full.match(/\?/)
|
45
|
-
sheet_name, address_path = address_path_full.split('?')
|
46
|
-
@current_sheet = open_sheet sheet_name
|
47
|
-
arrs = @current_sheet.read address_path, simple
|
48
|
-
# 除去不完整数据
|
49
|
-
if filter_nil
|
50
|
-
(arrs.size - 1).downto(0) do |i|
|
51
|
-
arr = arrs[i]
|
52
|
-
if arr[0] == nil or arr[1] == nil
|
53
|
-
arrs.delete_at i
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
36
|
+
# Example: address = "Sheet1?a1:f5"
|
37
|
+
def read params, show_location = false
|
57
38
|
|
58
|
-
|
39
|
+
case params.class.to_s
|
40
|
+
when 'String'
|
41
|
+
shett_name, scope = params.split('?')
|
42
|
+
@current_sheet = open_sheet shett_name
|
43
|
+
@current_sheet.read scope, show_location
|
44
|
+
when 'Hash'
|
45
|
+
raise "Parameter error! \nnot find 'sheet'" if params[:sheet].nil?
|
46
|
+
raise "Parameter error! \nnot find 'scope'" if params[:scope].nil?
|
47
|
+
params[:location] = false if params[:location].nil?
|
48
|
+
@current_sheet = open_sheet params[:sheet]
|
49
|
+
@current_sheet.read params, params[:location]
|
50
|
+
end
|
59
51
|
end
|
60
52
|
|
53
|
+
|
61
54
|
# 保存文件
|
62
55
|
def save path
|
63
|
-
puts "
|
56
|
+
puts "Covers a file: #{path}" if File.exist? path
|
64
57
|
@excel.write path
|
65
|
-
puts "
|
58
|
+
puts "Excel save success!"
|
66
59
|
self
|
67
60
|
end
|
68
61
|
|
data/lib/ld/excel/sheet.rb
CHANGED
@@ -9,7 +9,7 @@ class Ld::Sheet
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize excel, name, type = 'new'
|
12
|
-
raise "name
|
12
|
+
raise "sheet name is nil" if !name
|
13
13
|
@excel = excel
|
14
14
|
@name = name
|
15
15
|
case type
|
@@ -20,226 +20,146 @@ class Ld::Sheet
|
|
20
20
|
@rows = []
|
21
21
|
when 'open'
|
22
22
|
@sheet = excel.worksheet name
|
23
|
-
raise "#{name}
|
23
|
+
raise "sheet '#{name}' not found!" if !@sheet
|
24
24
|
end
|
25
25
|
@format = @sheet.default_format
|
26
26
|
end
|
27
27
|
|
28
|
-
def read
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
puts "没有任何内容的区域! #{address_str}"
|
33
|
-
else
|
34
|
-
puts "#{address_str}"
|
35
|
-
end
|
36
|
-
arrs
|
28
|
+
def read scope, show_location = false
|
29
|
+
raise "scope params is nil" if !scope
|
30
|
+
map = parse_scope_to_map scope
|
31
|
+
read_arrs map, show_location
|
37
32
|
end
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
def parse_string_scope scope
|
35
|
+
hash = {}
|
36
|
+
scope.upcase!
|
37
|
+
raise "params error! \n'+' 只能有1个" if scope.split('+').size > 2
|
38
|
+
raise "params error! \n'-' 只能有1个" if scope.split('-').size > 2
|
39
|
+
if scope.include? '+'
|
40
|
+
hash[:scope], other = scope.split('+')
|
41
|
+
if other.include? '-'
|
42
|
+
hash[:adds], hash[:mins] = other.split('-')
|
43
|
+
else
|
44
|
+
hash[:adds] = other
|
45
|
+
end
|
46
|
+
else
|
47
|
+
if scope.include? '-'
|
48
|
+
hash[:scope], hash[:mins] = scope.split('-')
|
49
|
+
else
|
50
|
+
hash[:scope] = scope
|
50
51
|
end
|
51
|
-
@scope_arrs << rows
|
52
52
|
end
|
53
|
-
|
53
|
+
hash
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if
|
61
|
-
|
62
|
-
|
56
|
+
def parse_scope_to_map scope
|
57
|
+
scope = parse_string_scope scope if scope.class == String
|
58
|
+
raise "params lack fields ':scope'!" if !scope[:scope]
|
59
|
+
raise "params syntax error! lack ':'" if !scope[:scope].match(/:/)
|
60
|
+
raise "params syntax error! ':' 只能有1个" if scope[:scope].split(':').size > 2
|
61
|
+
a, b = scope[:scope].split(':').map{|point| parse_point point}
|
62
|
+
cols = (a[:character]..b[:character]).to_a
|
63
|
+
rows = (a[:number]..b[:number]).to_a
|
64
|
+
maps_add rows, cols, scope[:adds].upcase if scope[:adds]
|
65
|
+
maps_min rows, cols, scope[:mins].upcase if scope[:mins]
|
66
|
+
|
67
|
+
if scope[:mins]
|
68
|
+
raise "mins 参数只能是 String" if scope[:mins].class != String
|
69
|
+
end
|
70
|
+
rows = rows.uniq.sort
|
71
|
+
cols = cols.uniq.sort
|
72
|
+
maps = rows.map do |row|
|
73
|
+
cols.map do |col|
|
74
|
+
col_i = ABSCISSA[col]
|
75
|
+
raise "不存在这个列 \n'#{col}'" if !col_i
|
76
|
+
{
|
77
|
+
location:"#{col}#{row}",
|
78
|
+
row:row,
|
79
|
+
col:col_i
|
80
|
+
}
|
63
81
|
end
|
64
82
|
end
|
65
|
-
|
83
|
+
# 调试
|
84
|
+
# maps.each do |arr|
|
85
|
+
# puts arr.map{|a| a[:location]}.to_s
|
86
|
+
# end
|
87
|
+
maps
|
66
88
|
end
|
67
89
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
arr = config[:scope].split(':')
|
76
|
-
if config[:scope].scan(/[0-9]+/).join == ''
|
77
|
-
map_adds(map, ab_to(arr[0].scan(/[A-Z]+/).join, arr[1].scan(/[A-Z]+/).join))
|
78
|
-
elsif config[:scope].scan(/[A-Z]+/).join == ''
|
79
|
-
map_adds(map, ab_to(arr[0].scan(/[0-9]+/).join, arr[1].scan(/[0-9]+/).join))
|
80
|
-
else
|
81
|
-
map_adds(map, ab_to(arr[0].scan(/[0-9]+/).join, arr[1].scan(/[0-9]+/).join))
|
82
|
-
map_adds(map, ab_to(arr[0].scan(/[A-Z]+/).join, arr[1].scan(/[A-Z]+/).join))
|
83
|
-
end
|
84
|
-
# map 添加
|
85
|
-
if config[:add_str]
|
86
|
-
config[:add_str].split(',').each do |add|
|
87
|
-
if add.include? ":"
|
88
|
-
map_adds(map, ab_to(add.split(':')[0], add.split(':')[1]))
|
89
|
-
else
|
90
|
-
map_add map, add
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
# map 减小
|
95
|
-
if config[:min_str]
|
96
|
-
config[:min_str].split(',').each do |min|
|
97
|
-
if min.include? ":"
|
98
|
-
map_mins(map, ab_to(min.split(':')[0], min.split(':')[1]))
|
99
|
-
else
|
100
|
-
map_min map, min
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
90
|
+
def maps_add rows, cols, adds
|
91
|
+
raise "adds 参数只能是 String" if adds.class != String
|
92
|
+
add_arr = adds.split(',').map do |add|
|
93
|
+
if add.match(/:/)
|
94
|
+
raise "add params syntax error! \n'#{add}'" if add.split(':').size > 2
|
95
|
+
a, b = add.split(':')
|
96
|
+
(a..b).to_a
|
104
97
|
else
|
105
|
-
|
98
|
+
add
|
106
99
|
end
|
107
|
-
else
|
108
|
-
raise "scope == nil"
|
109
100
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
map[:x].each do |x|
|
116
|
-
rows << ["#{x}_#{y}", ABSCISSA[x], y.to_i - 1]
|
101
|
+
add_arr.flatten.each do |add|
|
102
|
+
if is_row? add
|
103
|
+
rows << add.to_i
|
104
|
+
else
|
105
|
+
cols << add.upcase
|
117
106
|
end
|
118
|
-
arrs << rows
|
119
107
|
end
|
120
|
-
return arrs
|
121
|
-
rescue
|
122
|
-
puts "生成map时发生错误: #{$!}"
|
123
|
-
puts $@
|
124
108
|
end
|
125
109
|
|
126
|
-
def
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
when 0
|
136
|
-
return [type, [a]]
|
110
|
+
def maps_min rows, cols, mins
|
111
|
+
raise "mins 参数只能是 String" if mins.class != String
|
112
|
+
min_arr = mins.split(',').map do |min|
|
113
|
+
if min.match(/:/)
|
114
|
+
raise "min params syntax error! \n'#{min}'" if min.split(':').size > 2
|
115
|
+
a, b = min.split(':')
|
116
|
+
(a..b).to_a
|
117
|
+
else
|
118
|
+
min
|
137
119
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
return [type, (a..b).to_a]
|
145
|
-
when 0
|
146
|
-
return [type, [a]]
|
120
|
+
end
|
121
|
+
min_arr.flatten.each do |min|
|
122
|
+
if is_row? min
|
123
|
+
rows.delete min.to_i
|
124
|
+
else
|
125
|
+
cols.delete min.upcase
|
147
126
|
end
|
148
|
-
else
|
149
|
-
raise "解析excel配置范围时,':'两边必须要么都是字母,要么都是数字!"
|
150
127
|
end
|
151
128
|
end
|
152
129
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
130
|
+
# show_location 带不带坐标index数据
|
131
|
+
def read_arrs map_arrs, show_location
|
132
|
+
map_arrs.map do |map_arr|
|
133
|
+
map_arr.map do |map|
|
134
|
+
value = read_unit_by_xy map[:col], map[:row], true
|
135
|
+
if show_location
|
136
|
+
{map[:location] => value}
|
137
|
+
else
|
138
|
+
value
|
162
139
|
end
|
140
|
+
end
|
163
141
|
end
|
164
142
|
end
|
165
143
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
def map_adds map, adds
|
175
|
-
case adds[0]
|
176
|
-
when 'x'
|
177
|
-
adds[1].each do |add|
|
178
|
-
map[:x] << add
|
179
|
-
end
|
180
|
-
when 'y'
|
181
|
-
adds[1].each do |add|
|
182
|
-
map[:y] << add
|
183
|
-
end
|
144
|
+
# 通过x,y坐标获取unit内容
|
145
|
+
def read_unit_by_xy x, y, parse
|
146
|
+
# puts "x: #{x}\ty: #{y}"
|
147
|
+
unit = @sheet.row(y)[x]
|
148
|
+
if unit.instance_of? Spreadsheet::Formula
|
149
|
+
if parse
|
150
|
+
return unit.value
|
151
|
+
end
|
184
152
|
end
|
153
|
+
return unit
|
185
154
|
end
|
186
155
|
|
187
|
-
def
|
188
|
-
if
|
156
|
+
def is_row? row
|
157
|
+
if row.to_i.to_s == row.to_s
|
189
158
|
return true
|
190
159
|
end
|
191
160
|
false
|
192
161
|
end
|
193
162
|
|
194
|
-
def map_add map, add
|
195
|
-
if is_number? add
|
196
|
-
map[:y] << add
|
197
|
-
else
|
198
|
-
map[:x] << add
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# 解析范围配置
|
203
|
-
def parse_address address
|
204
|
-
hash = {}
|
205
|
-
if address
|
206
|
-
address.upcase!
|
207
|
-
else
|
208
|
-
raise "address 为 nil"
|
209
|
-
end
|
210
|
-
if address.split('+').size > 2
|
211
|
-
raise "'+'号只能有1个"
|
212
|
-
end
|
213
|
-
if address.split('-').size > 2
|
214
|
-
raise "'-'号只能有1个"
|
215
|
-
end
|
216
|
-
if address.include?('+')
|
217
|
-
a = address.split('+')[0]
|
218
|
-
b = address.split('+')[1]
|
219
|
-
if a.include?('-')
|
220
|
-
hash.store :scope, a.split('-')[0]
|
221
|
-
hash.store :min_str, a.split('-')[1]
|
222
|
-
hash.store :add_str, b
|
223
|
-
else
|
224
|
-
hash.store :scope, a
|
225
|
-
if b.include?('-')
|
226
|
-
hash.store :min_str, b.split('-')[1]
|
227
|
-
hash.store :add_str, b.split('-')[0]
|
228
|
-
else
|
229
|
-
hash.store :add_str, b
|
230
|
-
end
|
231
|
-
end
|
232
|
-
else
|
233
|
-
if address.include?('-')
|
234
|
-
hash.store :scope, address.split('-')[0]
|
235
|
-
hash.store :min_str, address.split('-')[1]
|
236
|
-
else
|
237
|
-
hash.store :scope, address
|
238
|
-
end
|
239
|
-
end
|
240
|
-
hash
|
241
|
-
end
|
242
|
-
|
243
163
|
def self.open excel, name
|
244
164
|
self.new excel, name, 'open'
|
245
165
|
end
|
@@ -249,24 +169,30 @@ class Ld::Sheet
|
|
249
169
|
end
|
250
170
|
|
251
171
|
def save
|
252
|
-
|
172
|
+
point = parse_point @point
|
253
173
|
raise '保存sheet必须要有内容,请 set_rows' if !@rows
|
254
174
|
raise '保存sheet必须要有name,请 set_rows' if !@name
|
255
175
|
@rows.unshift @headings if @headings
|
256
176
|
@sheet.default_format = @format
|
257
|
-
@rows.each_with_index do |row,r|
|
258
|
-
row.each_with_index do |
|
259
|
-
|
177
|
+
@rows.each_with_index do |row, r|
|
178
|
+
row.each_with_index do |unit, c|
|
179
|
+
x = point[:number] + r
|
180
|
+
y = ABSCISSA[point[:character]] + c
|
181
|
+
write_unit_by_xy x, y, unit
|
260
182
|
end
|
261
183
|
end
|
262
184
|
self
|
263
185
|
end
|
264
186
|
|
265
187
|
# 解析一个 content_url
|
266
|
-
def
|
267
|
-
raise "无法解析excel坐标,坐标需要是String,不能是#{
|
268
|
-
|
269
|
-
|
188
|
+
def parse_point point
|
189
|
+
raise "无法解析excel坐标,坐标需要是String,不能是#{point.class.to_s}" if point.class != String
|
190
|
+
point.upcase!
|
191
|
+
characters = point.scan(/[A-Z]+/)
|
192
|
+
raise "parse point error! \n'#{point}'" if characters.size != 1
|
193
|
+
numbers = point.scan(/[0-9]+/)
|
194
|
+
raise "parse point error! \n'#{point}'" if numbers.size != 1
|
195
|
+
{:character => characters[0], :number => numbers[0].to_i}
|
270
196
|
end
|
271
197
|
|
272
198
|
def set_rows rows
|
@@ -297,25 +223,6 @@ class Ld::Sheet
|
|
297
223
|
@sheet.row(x)[y] = unit
|
298
224
|
end
|
299
225
|
|
300
|
-
# 将一维数组写到表中,可写成列,也可以写成行
|
301
|
-
def write_arr_to_point(arr, rank = '|', point = "a1")
|
302
|
-
l = Ld::Excel.parse_location(point)
|
303
|
-
if rank == '|' or rank == 'col'
|
304
|
-
arr.each_with_index do |data,r|
|
305
|
-
# 坚写,行动列不动
|
306
|
-
write_unit_by_xy(l[:r]+r,l[:c],data)
|
307
|
-
end
|
308
|
-
elsif rank == '-' or rank == 'row'
|
309
|
-
arr.each_with_index do |data,c|
|
310
|
-
# 横写,列动行不动
|
311
|
-
write_unit_by_xy(l[:r],l[:c]+c,data)
|
312
|
-
end
|
313
|
-
else
|
314
|
-
raise "横写rank | 竖写rank - 无法识别#{rank}"
|
315
|
-
end
|
316
|
-
self
|
317
|
-
end
|
318
|
-
|
319
226
|
def set_color color
|
320
227
|
@format.font.color = color
|
321
228
|
end
|
data/lib/ld/file/file.rb
CHANGED
@@ -3,6 +3,7 @@ class Ld::File
|
|
3
3
|
attr_accessor :path, :base_name, :name, :type
|
4
4
|
|
5
5
|
def initialize path
|
6
|
+
# raise "file is not found!\n#{path}" if !File.exist? path
|
6
7
|
@path = path
|
7
8
|
@name = File.basename @path
|
8
9
|
@base_name = name.split('.')[0]
|
@@ -13,6 +14,14 @@ class Ld::File
|
|
13
14
|
Ld::File.new path
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.open path
|
18
|
+
if File.exist? path
|
19
|
+
self.new path
|
20
|
+
else
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
def brothers
|
17
26
|
father.children
|
18
27
|
end
|
data/lib/ld/project/project.rb
CHANGED
@@ -21,13 +21,14 @@ class Ld::Project
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def print model_name, type = :relations
|
24
|
+
model_name = model_name.to_s
|
24
25
|
if !@models.models.include? model_name
|
25
26
|
puts "不存在 #{model_name}"
|
26
27
|
return false
|
27
28
|
end
|
28
29
|
|
29
30
|
title_str = "#{model_name.camelize}(#{@table_hash[model_name]})"
|
30
|
-
|
31
|
+
type = type.to_sym
|
31
32
|
case type
|
32
33
|
when :fields
|
33
34
|
fs = '字段,字段类型,描述,空约束,默认值,精度位数,limit'.split(',')
|
@@ -94,7 +95,7 @@ class Ld::Project
|
|
94
95
|
@controllers.rows.delete_at 0
|
95
96
|
end
|
96
97
|
|
97
|
-
def to_xls path = "#{@root.path}/project.xls"
|
98
|
+
def to_xls path = {:file_path => "#{@root.path}/project.xls"}
|
98
99
|
Ld::Excel.create path do |excel|
|
99
100
|
excel.write_sheet 'routes' do |sheet|
|
100
101
|
sheet.set_format({color: :red, font_size: 14, font: '微软雅黑'})
|
data/lib/ld/version.rb
CHANGED