Class: Aio::Base::Toolkit::ExcelWps::WorkBook
- Inherits:
-
Object
- Object
- Aio::Base::Toolkit::ExcelWps::WorkBook
show all
- Includes:
- Ui::Verbose
- Defined in:
- lib/aio/base/toolkit/excel_wps.rb
Constant Summary
collapse
- @@worksheets_name =
[]
Class Method Summary
collapse
Instance Method Summary
collapse
#clear_line, #print_error, #print_good, #progress_bar
Constructor Details
#initialize(encoding = "utf-8") ⇒ WorkBook
Returns a new instance of WorkBook.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 8
def initialize(encoding = "utf-8")
if Aio::Base::Toolkit::OS.windows?
require "win32ole"
else
print_error "只有Windows系统才能使用Excel模块"
exit 0
end
@excel = WIN32OLE.new("excel.Application")
@excel.visible = false
@workbook = @excel.workbooks.add
@encoding = encoding
create_style
end
|
Class Method Details
.bold_style(sty) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 64
def self.bold_style(sty)
sty.font.size = 9
sty.font.bold = true
sty.borders(7).linestyle = 1
sty.borders(8).linestyle = 1
sty.borders(9).linestyle = 1
sty.borders(10).linestyle = 1
sty.HorizontalAlignment = -4108
end
|
.normal_style(sty) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 55
def self.normal_style(sty)
sty.font.size = 9
sty.borders(7).linestyle = 1
sty.borders(8).linestyle = 1
sty.borders(9).linestyle = 1
sty.borders(10).linestyle = 1
sty.HorizontalAlignment = -4108
end
|
.title_style(sty) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 74
def self.title_style(sty)
sty.font.size = 20
sty.font.bold = true
sty.borders(7).linestyle = 1
sty.borders(8).linestyle = 1
sty.borders(9).linestyle = 1
sty.borders(10).linestyle = 1
sty.HorizontalAlignment = -4108
end
|
Instance Method Details
#add_worksheet(name) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 30
def add_worksheet(name)
while @@worksheets_name.include?(name)
name += "1"
end
@@worksheets_name << name
worksheet = @workbook.worksheets.add
worksheet.activate
worksheet.name = "sheet"
return WorkSheet.new(worksheet)
end
|
#close ⇒ Object
92
93
94
95
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 92
def close
@workbook.close
@excel.quit
end
|
#create_style ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 44
def create_style
sty = @workbook.styles.add("NormalStyle")
self.class.normal_style(sty)
sty = @workbook.styles.add("BoldStyle")
self.class.bold_style(sty)
sty = @workbook.styles.add("TitleStyle")
self.class.title_style(sty)
end
|
#display_alerts=(bool) ⇒ Object
26
27
28
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 26
def display_alerts=(bool)
@excel.DisplayAlerts = bool
end
|
#save(path) ⇒ Object
88
89
90
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 88
def save(path)
@workbook.saveas(path)
end
|
#show ⇒ Object
84
85
86
|
# File 'lib/aio/base/toolkit/excel_wps.rb', line 84
def show
@excel.visible = true
end
|