aio_elin 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,492 +1,496 @@
1
1
  module Aio::Base::Toolkit
2
- module WordWps
3
- class Word
4
-
5
- include Aio::Ui::Verbose
6
-
7
- def initialize(encoding = "utf-8")
8
-
9
- if Aio::Base::Toolkit::OS.windows?
10
- require "win32ole"
11
- else
12
- print_error "只有Windows系统才能使用Excel模块"
13
- exit 0
14
- end
15
-
16
-
17
- @word = WIN32OLE.new("Word.Application")
18
- @word.visible = false
19
- @encoding = encoding
20
- end
21
-
22
- # 警告提示开关
23
- def display_alerts=(bool)
24
- @word.DisplayAlerts = bool
25
- end
26
-
27
- def init_document
28
- @document = @word.Documents.add
29
- return Document.new(@document, @word)
30
- end
31
-
32
-
33
- def show
34
- @word.visible = true
35
- end
36
-
37
- def save(path)
38
- @document.saveas(path)
39
- end
40
-
41
- def close
42
- @document.close
43
- @word.quit
44
- end
45
- end
46
-
47
- # 对文本控件的调用
48
- class Document
49
-
50
- def initialize(document, word)
51
- @doc_work = document
52
- @word = word
53
- #@text = Text.new(@word.Selection, self)
54
- create_style
55
- end
56
-
57
- # ActiveDocument
58
- def doc_work
59
- @doc_work
60
- end
61
-
62
- # 自动化对象
63
- def word_basic
64
- doc_work.Application.WordBasic
65
- end
66
-
67
- # 创建样式
68
- def create_style
69
-
70
- # 正文 楷体五号
71
- sty = @doc_work.styles("正文")
72
- sty.font.size = 10
73
- sty.font.NameFarEast = "宋体"
74
- sty.font.NameAscii = "Times New Roman"
75
- sty.font.NameOther = "Times New Roman"
76
- sty.ParagraphFormat.Alignment = 3
77
- sty.ParagraphFormat.LineSpacingRule = 1
78
- sty.NextParagraphStyle = "正文"
79
-
80
- # 楷体3号字体
81
- sty = @doc_work.styles.add("Cover 1", 1)
82
- sty.font.size = 16
83
- sty.font.NameFarEast = "楷体"
84
- sty.font.NameAscii = "Times New Roman"
85
- sty.font.NameOther = "Times New Roman"
86
- end
87
-
88
- # 由实例自己创建风格
89
- def create_style_self(name)
90
- sty = @doc_work.styles.add(name, 1)
91
- yield sty
92
- end
93
-
94
- # 返回Selection
95
- def now
96
- @word.Selection
97
- end
98
-
99
- # 返回Text类
100
- def add_text
101
- return Text.new(@word.Selection, self)
102
- entry
103
- end
104
-
105
- # 风格设置
106
- def styles(name)
107
- @doc_work.Styles(name)
108
- end
109
-
110
- # 设置表格
111
- def add_table(row, col)
112
- @doc_work.tables.add(now.Range, row, col)
113
- end
114
-
115
- # 创建目录
116
- def create_catalog
117
- #range = doc_work.Range(0, 0)
118
- range = now.range
119
- doc_work.TablesOfContents.Add(
120
- range, # Range
121
- true, # UseHeadingStyles
122
- 1, # UpperHeadingLevel
123
- 3, # LowerHeadingLevel default: 9
124
- false, # UseFields
125
- nil, # TableId
126
- true, # RightAlignPageNumbers
127
- true, # IncludePageNumbers
128
- "", # AddedStyles
129
- true, # UseHyperlinks
130
- true, # HidePageNumbersInWeb
131
- true, # UseOutlineLevels default: false
132
- )
133
-
134
- # 换到下一行
135
- move_down
136
- end
137
-
138
- # 更新目录
139
- def update_catalog
140
- word_basic.UpdateTableOfContents
141
- end
142
-
143
- # 回车
144
- def entry
145
- now.TypeParagraph
146
- end
147
-
148
- # 移动到行首
149
- def home_key
150
- now.HomeKey(5)
151
- end
152
-
153
- # 移动到行尾
154
- def end_key
155
- now.EndKey(5)
156
- end
157
-
158
- # 移动到下一行
159
- def move_down
160
- self.end_key
161
- self.entry
162
- end
163
-
164
- # 右移
165
- # count 数值, 移动距离
166
- # ext 0or1 , 是否扩展
167
- # unit wdCharachter
168
- def move_right(count=nil, ext=nil, unit=nil)
169
- now.MoveRight(unit, count, ext)
170
- end
171
-
172
- # 将厘米换算成磅
173
- def cent_to_point(int)
174
- @word.CentimetersToPoints(int)
175
- end
176
-
177
- end
178
-
179
- # 只对内容服务
180
- class Text
181
-
182
- def initialize(selection, document)
183
- # 现在所选项
184
- @selection = selection
185
-
186
- # Document 类
187
- @document = document
188
- end
189
-
190
- # ActiveDocument
191
- def doc_work
192
- @document.doc_work
193
- end
194
-
195
- # ActiveDocument.Selecton
196
- def now
197
- @selection
198
- end
199
-
200
- # 调整字体
201
- def font
202
- now.Font
203
- end
204
-
205
- # 调整字体大小
206
- def size=(int)
207
- self.font.Size = int
208
- end
209
-
210
- # 文本左对齐
211
- def left
212
- now.ParagraphFormat.Alignment = 0
213
- end
214
-
215
- # 文本居中
216
- def center
217
- now.ParagraphFormat.Alignment = 1
218
- end
219
-
220
- # 文本右对齐
221
- def right
222
- now.ParagraphFormat.Alignment = 2
223
- end
224
-
225
- # 两端对其
226
- def justify
227
- now.ParagraphFormat.Alignment = 3
228
- end
229
-
230
- # 回车
231
- def entry
232
- @document.entry
233
- end
234
-
235
- # 移动到下一行
236
- def move_down
237
- @document.move_down
238
- end
239
-
240
- # 写入元数据
241
- def print(str)
242
- now.TypeText(str)
243
- end
244
-
245
- # 写入数据,抬头Tab, 并且换行
246
- def puts(str)
247
- now.TypeText("\t" + str)
248
- self.entry
249
- end
250
-
251
- # 替换,并替换风格
252
- def replace(find, replace, style)
253
- rep_opt = now.Find
254
- rep_opt.ClearFormatting
255
- rep_opt.Replacement.ClearFormatting
256
- rep_opt.Replacement.Style = doc_work.Styles(style)
257
- rep_opt.Text = find
258
- rep_opt.Replacement.Text = replace
259
- rep_opt.Forward = true
260
- rep_opt.wrap = 1 # 到达开头或结尾时继续搜索
261
- rep_opt.Format = true
262
- rep_opt.MatchCase = false
263
- rep_opt.MatchWholeWord = false
264
- rep_opt.MatchByte = true
265
- rep_opt.MatchWildcards = false
266
- rep_opt.MatchSoundsLike = false
267
- rep_opt.MatchAllWordForms = false
268
-
269
- rep_opt.Execute(nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,1)
270
- end
271
-
272
-
273
- # 设置风格
274
- def style(name)
275
- now.Style = @document.styles(name)
276
- end
277
-
278
- # 按一个段设置风格和内容
279
- def section(style_name=nil)
280
- self.style(style_name) unless style_name.nil?
281
- res = yield
282
- if res.kind_of? ::Array
283
- res.join("\n")
284
- end
285
- print(res)
286
- self.entry
287
- end
288
-
289
- # 插入表格,并返回Table类
290
- def insert_table(row, col)
291
- obj = @document.add_table(row, col)
292
- Table.new(now, row, col, obj)
293
- end
294
-
295
- # 插入表格
296
- def add_table(row, col, &block)
297
- table = insert_table(row, col)
298
- block.call(table)
299
-
300
- # 跳出表格
301
- now.MoveDown(5, 1)
302
- end
303
-
304
- # 通过已有的数组插入表格
305
- def add_table_by_value(tbl, &block)
306
- row = tbl.size
307
- col = tbl[0].size
308
- table = insert_table(row, col)
309
- block.call(table)
310
-
311
- # 保证在写入数据的时候在第一个单元格
312
- table.top
313
- # 一维化数组
314
- table << tbl.flatten
315
- # 跳出表格
316
- now.MoveDown(5, 1)
317
- end
318
-
319
- # 插入头部的图片
320
- def add_head_image(path)
321
- self.first_line_indent = -2
322
- add_image(path)
323
- picture_size(1.25)
324
- self.entry
325
- self.first_line_indent = 0
326
- end
327
-
328
- # 插入图片
329
- def add_image(path)
330
- now.InlineShapes.AddPicture(path, false, true)
331
- end
332
-
333
- # 修改首行缩进(厘米)
334
- def first_line_indent=(cent)
335
- now.ParagraphFormat.FirstLineIndent = @document.cent_to_point(cent)
336
- end
337
-
338
- # 修改最近一个图片尺寸倍数
339
- def picture_size(int)
340
- num = doc_work.InlineShapes.Count
341
- pic = doc_work.InlineShapes(num)
342
- pic.width *= int
343
- end
344
-
345
- # 插入一条横线
346
- def insert_line
347
-
348
- # 通过导入图片的方法
349
- path = File.join(BaseFile, "aio", "resource", "line.png")
350
- self.add_image(path)
351
- self.move_down
352
- end
353
-
354
- # 绘制图表
355
- # 测试图表
356
- #tbl = [
357
- # ["a", "1"],
358
- # ["b", "2"],
359
- # ["c", "3"],
360
- # ["d", "4"],
361
- #]
362
- #text.chart(tbl) do |chart|
363
- # chart.title = "Name"
364
- # chart.type = 5
365
- # #chart.axes_x = "year"
366
- # #chart.axes_y = "value"
367
- # chart.style = 251
368
- #end
369
- def chart(tbl, &block)
370
- begin
371
- excel = ExcelWps::WorkBook.new
372
- #excel.show
373
- excel.display_alerts = false
374
- worksheet = excel.add_worksheet("sheet")
375
- tbl.each do |r|
376
- worksheet.add_row { |row| row << r }
377
- end
378
-
379
- # 获取结束的单元格
380
- col = tbl[0].size
381
- end_cell = worksheet.current_row.cell_name(col - 1)
382
-
383
- worksheet.add_chart do |chart|
384
- chart.source = worksheet.range("A1:#{end_cell}")
385
- block.call(chart)
386
- end
387
- ensure
388
- excel.close
389
- end
390
-
391
- self.style("正文")
392
- self.center
393
- doc_work.Application.Selection.PasteAndFormat(13)
394
-
395
- # 移动到下一行
396
- self.move_down
397
- self.left
398
- end
399
-
400
- # 插入分页符
401
- def page_break
402
- now.InsertBreak(7)
403
- end
404
-
405
- alias :style= :style
406
- end
407
-
408
- # 表格
409
- class Table
410
- def initialize(selection, row, col, obj)
411
- @row = row
412
- @col = col
413
- @count = row * col
414
- @selection = selection
415
- @obj = obj
416
- end
417
-
418
- def now
419
- @selection
420
- end
421
-
422
- # 合并列
423
- def merge_row
424
- now.SelectRow
425
- now.Cells.Merge
426
- @count = @count - @row + 1
427
- end
428
-
429
- # 放入数据
430
- def puts(str)
431
- now.SelectCell
432
- now.TypeText(str)
433
- @count -= 1
434
- now.MoveRight(12) unless @count < 1
435
- end
436
-
437
- # 放入数据, 可以按数组放入
438
- def <<(arr)
439
- case arr
440
- when ::String
441
- puts(arr)
442
- when ::Array
443
- arr.each { |a| puts(a) }
444
- end
445
- end
446
-
447
- # 设置行高
448
- def height=(point)
449
- now.Rows.Height = point
450
- end
451
-
452
- # 设置风格
453
- def style=(sty)
454
- select_all
455
- now.Style = sty
456
- end
457
-
458
- # 设置列宽度
459
- def set_columns_width(col, point)
460
- @obj.Columns(col).SetWidth(point, 2)
461
- end
462
-
463
- # 移动到第一个单元格
464
- def top
465
- @obj.Cell(1,1).Select
466
- end
467
-
468
- # 居中
469
- def center
470
- select_all
471
- now.ParagraphFormat.Alignment = 1
472
- end
473
-
474
- # 选择整个表格
475
- def select_all
476
- @obj.Select
477
- end
478
-
479
- # 网格线
480
- def border_line
481
- select_all
482
- now.Borders(-1).LineStyle = 1
483
- now.Borders(-2).LineStyle = 1
484
- now.Borders(-3).LineStyle = 1
485
- now.Borders(-4).LineStyle = 1
486
- now.Borders(-5).LineStyle = 1
487
- now.Borders(-6).LineStyle = 1
488
- end
489
- end
490
-
491
- end
2
+ module WordWps
3
+ class Word
4
+
5
+ include Aio::Ui::Verbose
6
+
7
+ def initialize(encoding = "utf-8")
8
+
9
+ if Aio::Base::Toolkit::OS.windows?
10
+ require "win32ole"
11
+ else
12
+ print_error "只有Windows系统才能使用Excel模块"
13
+ exit 0
14
+ end
15
+
16
+
17
+ @word = WIN32OLE.new("Word.Application")
18
+ @word.visible = false
19
+ @encoding = encoding
20
+ end
21
+
22
+ # 警告提示开关
23
+ def display_alerts=(bool)
24
+ @word.DisplayAlerts = bool
25
+ end
26
+
27
+ def init_document
28
+ @document = @word.Documents.add
29
+ return Document.new(@document, @word)
30
+ end
31
+
32
+
33
+ def show
34
+ @word.visible = true
35
+ end
36
+
37
+ def save(path)
38
+ @document.saveas(path)
39
+ end
40
+
41
+ def close
42
+ @document.close
43
+ @word.quit
44
+ end
45
+ end
46
+
47
+ # 对文本控件的调用
48
+ class Document
49
+
50
+ def initialize(document, word)
51
+ @doc_work = document
52
+ @word = word
53
+ #@text = Text.new(@word.Selection, self)
54
+ create_style
55
+ end
56
+
57
+ # ActiveDocument
58
+ def doc_work
59
+ @doc_work
60
+ end
61
+
62
+ # 自动化对象
63
+ def word_basic
64
+ doc_work.Application.WordBasic
65
+ end
66
+
67
+ # 创建样式
68
+ def create_style
69
+
70
+ # 正文 楷体五号
71
+ sty = @doc_work.styles("正文")
72
+ sty.font.size = 10
73
+ sty.font.NameFarEast = "宋体"
74
+ sty.font.NameAscii = "Times New Roman"
75
+ sty.font.NameOther = "Times New Roman"
76
+ sty.ParagraphFormat.Alignment = 3
77
+ sty.ParagraphFormat.LineSpacingRule = 1
78
+ sty.NextParagraphStyle = "正文"
79
+
80
+ # 楷体3号字体
81
+ sty = @doc_work.styles.add("Cover 1", 1)
82
+ sty.font.size = 16
83
+ sty.font.NameFarEast = "楷体"
84
+ sty.font.NameAscii = "Times New Roman"
85
+ sty.font.NameOther = "Times New Roman"
86
+ end
87
+
88
+ # 由实例自己创建风格
89
+ def create_style_self(name)
90
+ sty = @doc_work.styles.add(name, 1)
91
+ yield sty
92
+ end
93
+
94
+ # 返回Selection
95
+ def now
96
+ @word.Selection
97
+ end
98
+
99
+ # 返回Text类
100
+ def add_text
101
+ return Text.new(@word.Selection, self)
102
+ entry
103
+ end
104
+
105
+ # 风格设置
106
+ def styles(name)
107
+ @doc_work.Styles(name)
108
+ end
109
+
110
+ # 设置表格
111
+ def add_table(row, col)
112
+ @doc_work.tables.add(now.Range, row, col)
113
+ end
114
+
115
+ # 创建目录
116
+ def create_catalog
117
+ #range = doc_work.Range(0, 0)
118
+ range = now.range
119
+ doc_work.TablesOfContents.Add(
120
+ range, # Range
121
+ true, # UseHeadingStyles
122
+ 1, # UpperHeadingLevel
123
+ 3, # LowerHeadingLevel default: 9
124
+ false, # UseFields
125
+ nil, # TableId
126
+ true, # RightAlignPageNumbers
127
+ true, # IncludePageNumbers
128
+ "", # AddedStyles
129
+ true, # UseHyperlinks
130
+ true, # HidePageNumbersInWeb
131
+ true, # UseOutlineLevels default: false
132
+ )
133
+
134
+ # 换到下一行
135
+ move_down
136
+ end
137
+
138
+ # 更新目录
139
+ def update_catalog
140
+ word_basic.UpdateTableOfContents
141
+ end
142
+
143
+ # 回车
144
+ def entry
145
+ now.TypeParagraph
146
+ end
147
+
148
+ # 移动到行首
149
+ def home_key
150
+ now.HomeKey(5)
151
+ end
152
+
153
+ # 移动到行尾
154
+ def end_key
155
+ now.EndKey(5)
156
+ end
157
+
158
+ # 移动到下一行
159
+ def move_down
160
+ self.end_key
161
+ self.entry
162
+ end
163
+
164
+ # 右移
165
+ # count 数值, 移动距离
166
+ # ext 0or1 , 是否扩展
167
+ # unit wdCharachter
168
+ def move_right(count=nil, ext=nil, unit=nil)
169
+ now.MoveRight(unit, count, ext)
170
+ end
171
+
172
+ # 将厘米换算成磅
173
+ def cent_to_point(int)
174
+ @word.CentimetersToPoints(int)
175
+ end
176
+
177
+ end
178
+
179
+ # 只对内容服务
180
+ class Text
181
+
182
+ def initialize(selection, document)
183
+ # 现在所选项
184
+ @selection = selection
185
+
186
+ # Document 类
187
+ @document = document
188
+ end
189
+
190
+ # ActiveDocument
191
+ def doc_work
192
+ @document.doc_work
193
+ end
194
+
195
+ # ActiveDocument.Selecton
196
+ def now
197
+ @selection
198
+ end
199
+
200
+ # 调整字体
201
+ def font
202
+ now.Font
203
+ end
204
+
205
+ # 调整字体大小
206
+ def size=(int)
207
+ self.font.Size = int
208
+ end
209
+
210
+ # 文本左对齐
211
+ def left
212
+ now.ParagraphFormat.Alignment = 0
213
+ end
214
+
215
+ # 文本居中
216
+ def center
217
+ now.ParagraphFormat.Alignment = 1
218
+ end
219
+
220
+ # 文本右对齐
221
+ def right
222
+ now.ParagraphFormat.Alignment = 2
223
+ end
224
+
225
+ # 两端对其
226
+ def justify
227
+ now.ParagraphFormat.Alignment = 3
228
+ end
229
+
230
+ # 回车
231
+ def entry
232
+ @document.entry
233
+ end
234
+
235
+ # 移动到下一行
236
+ def move_down
237
+ @document.move_down
238
+ end
239
+
240
+ # 写入元数据
241
+ def print(str)
242
+ now.TypeText(str)
243
+ end
244
+
245
+ # 写入数据,抬头Tab, 并且换行
246
+ def puts(str)
247
+ now.TypeText("\t" + str)
248
+ self.entry
249
+ end
250
+
251
+ # 替换,并替换风格
252
+ def replace(find, replace, style)
253
+ rep_opt = now.Find
254
+ rep_opt.ClearFormatting
255
+ rep_opt.Replacement.ClearFormatting
256
+ rep_opt.Replacement.Style = doc_work.Styles(style)
257
+ rep_opt.Text = find
258
+ rep_opt.Replacement.Text = replace
259
+ rep_opt.Forward = true
260
+ rep_opt.wrap = 1 # 到达开头或结尾时继续搜索
261
+ rep_opt.Format = true
262
+ rep_opt.MatchCase = false
263
+ rep_opt.MatchWholeWord = false
264
+ rep_opt.MatchByte = true
265
+ rep_opt.MatchWildcards = false
266
+ rep_opt.MatchSoundsLike = false
267
+ rep_opt.MatchAllWordForms = false
268
+
269
+ rep_opt.Execute(nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,1)
270
+ end
271
+
272
+
273
+ # 设置风格
274
+ def style(name)
275
+ now.Style = @document.styles(name)
276
+ end
277
+
278
+ # 按一个段设置风格和内容
279
+ def section(style_name=nil)
280
+ self.style(style_name) unless style_name.nil?
281
+ res = yield
282
+ if res.kind_of? ::Array
283
+ res.join("\n")
284
+ end
285
+ print(res)
286
+ self.entry
287
+ end
288
+
289
+ # 插入表格,并返回Table类
290
+ def insert_table(row, col)
291
+ obj = @document.add_table(row, col)
292
+ Table.new(now, row, col, obj)
293
+ end
294
+
295
+ # 插入表格
296
+ def add_table(row, col, &block)
297
+ table = insert_table(row, col)
298
+ block.call(table)
299
+
300
+ # 跳出表格
301
+ now.MoveDown(5, 1)
302
+ end
303
+
304
+ # 通过已有的数组插入表格
305
+ def add_table_by_value(tbl, &block)
306
+ row = tbl.size
307
+ col = tbl[0].size
308
+ table = insert_table(row, col)
309
+ block.call(table)
310
+
311
+ # 保证在写入数据的时候在第一个单元格
312
+ table.top
313
+ # 一维化数组
314
+ table << tbl.flatten
315
+ # 跳出表格
316
+ now.MoveDown(5, 1)
317
+ end
318
+
319
+ # 插入头部的图片
320
+ def add_head_image(path)
321
+ self.first_line_indent = -2
322
+ add_image(path)
323
+ picture_size(1.25)
324
+ self.entry
325
+ self.first_line_indent = 0
326
+ end
327
+
328
+ # 插入图片
329
+ def add_image(path)
330
+ now.InlineShapes.AddPicture(path, false, true)
331
+ end
332
+
333
+ # 修改首行缩进(厘米)
334
+ def first_line_indent=(cent)
335
+ now.ParagraphFormat.FirstLineIndent = @document.cent_to_point(cent)
336
+ end
337
+
338
+ # 修改最近一个图片尺寸倍数
339
+ def picture_size(int)
340
+ num = doc_work.InlineShapes.Count
341
+ pic = doc_work.InlineShapes(num)
342
+ pic.width *= int
343
+ end
344
+
345
+ # 插入一条横线
346
+ def insert_line
347
+
348
+ # 通过导入图片的方法
349
+ path = File.join(BaseFile, "aio", "resource", "line.png")
350
+ self.add_image(path)
351
+ self.move_down
352
+ end
353
+
354
+ # 绘制图表
355
+ # 测试图表
356
+ #tbl = [
357
+ # ["a", "1"],
358
+ # ["b", "2"],
359
+ # ["c", "3"],
360
+ # ["d", "4"],
361
+ #]
362
+ #text.chart(tbl) do |chart|
363
+ # chart.title = "Name"
364
+ # chart.type = 5
365
+ # #chart.axes_x = "year"
366
+ # #chart.axes_y = "value"
367
+ # chart.style = 251
368
+ #end
369
+ def chart(tbl, &block)
370
+
371
+ # 当没有内容的时候,则不绘制
372
+ return nil if tbl.empty?
373
+
374
+ begin
375
+ excel = ExcelWps::WorkBook.new
376
+ #excel.show
377
+ excel.display_alerts = false
378
+ worksheet = excel.add_worksheet("sheet")
379
+ tbl.each do |r|
380
+ worksheet.add_row { |row| row << r }
381
+ end
382
+
383
+ # 获取结束的单元格
384
+ col = tbl[0].size
385
+ end_cell = worksheet.current_row.cell_name(col - 1)
386
+
387
+ worksheet.add_chart do |chart|
388
+ chart.source = worksheet.range("A1:#{end_cell}")
389
+ block.call(chart)
390
+ end
391
+ ensure
392
+ excel.close
393
+ end
394
+
395
+ self.style("正文")
396
+ self.center
397
+ doc_work.Application.Selection.PasteAndFormat(13)
398
+
399
+ # 移动到下一行
400
+ self.move_down
401
+ self.left
402
+ end
403
+
404
+ # 插入分页符
405
+ def page_break
406
+ now.InsertBreak(7)
407
+ end
408
+
409
+ alias :style= :style
410
+ end
411
+
412
+ # 表格
413
+ class Table
414
+ def initialize(selection, row, col, obj)
415
+ @row = row
416
+ @col = col
417
+ @count = row * col
418
+ @selection = selection
419
+ @obj = obj
420
+ end
421
+
422
+ def now
423
+ @selection
424
+ end
425
+
426
+ # 合并列
427
+ def merge_row
428
+ now.SelectRow
429
+ now.Cells.Merge
430
+ @count = @count - @row + 1
431
+ end
432
+
433
+ # 放入数据
434
+ def puts(str)
435
+ now.SelectCell
436
+ now.TypeText(str)
437
+ @count -= 1
438
+ now.MoveRight(12) unless @count < 1
439
+ end
440
+
441
+ # 放入数据, 可以按数组放入
442
+ def <<(arr)
443
+ case arr
444
+ when ::String
445
+ puts(arr)
446
+ when ::Array
447
+ arr.each { |a| puts(a) }
448
+ end
449
+ end
450
+
451
+ # 设置行高
452
+ def height=(point)
453
+ now.Rows.Height = point
454
+ end
455
+
456
+ # 设置风格
457
+ def style=(sty)
458
+ select_all
459
+ now.Style = sty
460
+ end
461
+
462
+ # 设置列宽度
463
+ def set_columns_width(col, point)
464
+ @obj.Columns(col).SetWidth(point, 2)
465
+ end
466
+
467
+ # 移动到第一个单元格
468
+ def top
469
+ @obj.Cell(1,1).Select
470
+ end
471
+
472
+ # 居中
473
+ def center
474
+ select_all
475
+ now.ParagraphFormat.Alignment = 1
476
+ end
477
+
478
+ # 选择整个表格
479
+ def select_all
480
+ @obj.Select
481
+ end
482
+
483
+ # 网格线
484
+ def border_line
485
+ select_all
486
+ now.Borders(-1).LineStyle = 1
487
+ now.Borders(-2).LineStyle = 1
488
+ now.Borders(-3).LineStyle = 1
489
+ now.Borders(-4).LineStyle = 1
490
+ now.Borders(-5).LineStyle = 1
491
+ now.Borders(-6).LineStyle = 1
492
+ end
493
+ end
494
+
495
+ end
492
496
  end