modle_to_excel 0.1.4 → 0.1.5
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/lib/modle_to_excel/version.rb +1 -1
- data/lib/modle_to_excel.rb +25 -26
- 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: 2c48124492fcf95b198a3e7515fd6e78d90a993d
|
4
|
+
data.tar.gz: 5ac60806167ba3fcf373ece04162f1de238d0545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8049e95c484d59ff9a9c213e505da3b6788f29a0c8711680f44f2dae614b579bdb38727e1d86e1a6054436d130f17b534844b08d1fdf6364ccd9d00f1b36a2
|
7
|
+
data.tar.gz: ebaf36c582f858fe6223d760d159aa1352d180fb422f0229956f9d27ff28da05c308d91de5e12fe211cd4577e3ddcaafe48d650cf7781762a95eadffe65dcbb2
|
data/lib/modle_to_excel.rb
CHANGED
@@ -6,33 +6,32 @@ module ModleToExcel
|
|
6
6
|
Spreadsheet.client_encoding = "UTF-8"
|
7
7
|
book = Spreadsheet::Workbook.new
|
8
8
|
first_row = ["编号","字段","类型","注释"]
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
|
10
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
11
|
+
next if table.match(/\Aschema_migrations\z/)
|
12
|
+
begin
|
13
|
+
sheet = book.create_worksheet :name => table
|
14
|
+
#第一横行
|
15
|
+
sheet.row(0).concat first_row
|
16
|
+
num = 1
|
17
|
+
class_name = table.singularize.classify
|
18
|
+
class_name.constantize.columns.each do |column|
|
19
|
+
puts column
|
20
|
+
puts column.type
|
21
|
+
sheet[num, 0] = num
|
22
|
+
sheet[num, 1] = column.name
|
23
|
+
sheet[num, 2] = column.type.to_s
|
24
|
+
sheet[num, 3] = ""
|
25
|
+
num += 1
|
26
|
+
|
27
|
+
end
|
28
|
+
rescue Exception => e
|
29
|
+
puts "table"
|
30
|
+
puts table
|
31
|
+
table_names << table
|
32
|
+
next
|
33
|
+
end
|
27
34
|
end
|
28
|
-
|
29
|
-
# rescue Exception => e
|
30
|
-
# puts "table"
|
31
|
-
# puts table
|
32
|
-
# table_names << table
|
33
|
-
# next
|
34
|
-
# end
|
35
|
-
end
|
36
35
|
book.write "#{Rails.root}/public/#{file_name}.xls"
|
37
36
|
end
|
38
37
|
|