Class: WordWps::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/word_wps.rb

Overview

表格

Instance Method Summary collapse

Constructor Details

#initialize(selection, row, col, obj) ⇒ Table

Returns a new instance of Table.



408
409
410
411
412
413
414
# File 'lib/word_wps.rb', line 408

def initialize(selection, row, col, obj)
	@row = row
	@col = col
	@count = row * col
	@selection = selection
	@obj = obj
end

Instance Method Details

#<<(arr) ⇒ Object

放入数据, 可以按数组放入



436
437
438
439
440
441
442
443
# File 'lib/word_wps.rb', line 436

def <<(arr)
	case arr
	when ::String
		puts(arr)
	when ::Array
		arr.each { |a| puts(a) }
	end
end

#border_lineObject

网格线



478
479
480
481
482
483
484
485
486
# File 'lib/word_wps.rb', line 478

def border_line
	select_all
	now.Borders(-1).LineStyle = 1
	now.Borders(-2).LineStyle = 1
	now.Borders(-3).LineStyle = 1
	now.Borders(-4).LineStyle = 1
	now.Borders(-5).LineStyle = 1
	now.Borders(-6).LineStyle = 1
end

#centerObject

居中



467
468
469
470
# File 'lib/word_wps.rb', line 467

def center
	select_all
	now.ParagraphFormat.Alignment = 1
end

#height=(point) ⇒ Object

设置行高



446
447
448
# File 'lib/word_wps.rb', line 446

def height=(point)
	now.Rows.Height = point
end

#merge_rowObject

合并列



421
422
423
424
425
# File 'lib/word_wps.rb', line 421

def merge_row
	now.SelectRow
	now.Cells.Merge
	@count = @count - @row + 1
end

#nowObject



416
417
418
# File 'lib/word_wps.rb', line 416

def now
	@selection
end

#puts(str) ⇒ Object

放入数据



428
429
430
431
432
433
# File 'lib/word_wps.rb', line 428

def puts(str)
	now.SelectCell
	now.TypeText(str)
	@count -= 1
	now.MoveRight(12) unless @count < 1
end

#select_allObject

选择整个表格



473
474
475
# File 'lib/word_wps.rb', line 473

def select_all
	@obj.Select
end

#set_columns_width(col, point) ⇒ Object

设置列宽度



457
458
459
# File 'lib/word_wps.rb', line 457

def set_columns_width(col, point)
	@obj.Columns(col).SetWidth(point, 2)
end

#style=(sty) ⇒ Object

设置风格



451
452
453
454
# File 'lib/word_wps.rb', line 451

def style=(sty)
	select_all
	now.Style = sty
end

#topObject

移动到第一个单元格



462
463
464
# File 'lib/word_wps.rb', line 462

def top
	@obj.Cell(1,1).Select
end