Class: WordWps::Document

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

Overview

对文本控件的调用

Instance Method Summary collapse

Constructor Details

#initialize(document, word) ⇒ Document

Returns a new instance of Document.



48
49
50
51
52
53
# File 'lib/word_wps.rb', line 48

def initialize(document, word)
	@doc_work = document
	@word = word
	#@text = Text.new(@word.Selection, self)
	create_style
end

Instance Method Details

#add_table(row, col) ⇒ Object

设置表格



109
110
111
# File 'lib/word_wps.rb', line 109

def add_table(row, col)
	@doc_work.tables.add(now.Range, row, col)
end

#add_textObject

返回Text类



98
99
100
101
# File 'lib/word_wps.rb', line 98

def add_text
	return Text.new(@word.Selection, self)
	entry
end

#cent_to_point(int) ⇒ Object

将厘米换算成磅



171
172
173
# File 'lib/word_wps.rb', line 171

def cent_to_point(int)
	@word.CentimetersToPoints(int)
end

#create_catalogObject

创建目录



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/word_wps.rb', line 114

def create_catalog
	#range = doc_work.Range(0, 0)
	range = now.range
	doc_work.TablesOfContents.Add(
		range,		# Range
		true,			# UseHeadingStyles
		1,				# UpperHeadingLevel
		3,				# LowerHeadingLevel default: 9
		false,		# UseFields
		nil,			# TableId
		true,			# RightAlignPageNumbers
		true,			# IncludePageNumbers
		"",				# AddedStyles
		true,			# UseHyperlinks
		true,			# HidePageNumbersInWeb
		true,			# UseOutlineLevels default: false
	)

	# 换到下一行
	move_down
end

#create_styleObject

创建样式



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/word_wps.rb', line 66

def create_style

	# 正文 楷体五号
	sty = @doc_work.styles("正文")
	sty.font.size = 10
	sty.font.NameFarEast = "宋体"
	sty.font.NameAscii = "Times New Roman"
	sty.font.NameOther = "Times New Roman"
	sty.ParagraphFormat.Alignment = 3
	sty.ParagraphFormat.LineSpacingRule = 1
	sty.NextParagraphStyle = "正文"

	# 楷体3号字体
	sty = @doc_work.styles.add("Cover 1", 1)
	sty.font.size = 16
	sty.font.NameFarEast = "楷体"
	sty.font.NameAscii = "Times New Roman"
	sty.font.NameOther = "Times New Roman"
end

#create_style_self(name) {|sty| ... } ⇒ Object

由实例自己创建风格

Yields:

  • (sty)


87
88
89
90
# File 'lib/word_wps.rb', line 87

def create_style_self(name)
	sty = @doc_work.styles.add(name, 1)
	yield sty
end

#doc_workObject

ActiveDocument



56
57
58
# File 'lib/word_wps.rb', line 56

def doc_work
	@doc_work
end

#end_keyObject

移动到行尾



152
153
154
# File 'lib/word_wps.rb', line 152

def end_key
	now.EndKey(5)
end

#entryObject

回车



142
143
144
# File 'lib/word_wps.rb', line 142

def entry
	now.TypeParagraph
end

#home_keyObject

移动到行首



147
148
149
# File 'lib/word_wps.rb', line 147

def home_key
	now.HomeKey(5)
end

#move_downObject

移动到下一行



157
158
159
160
# File 'lib/word_wps.rb', line 157

def move_down
	self.end_key
	self.entry
end

#move_right(count = nil, ext = nil, unit = nil) ⇒ Object

右移count 数值, 移动距离ext 0or1 , 是否扩展unit wdCharachter



166
167
168
# File 'lib/word_wps.rb', line 166

def move_right(count=nil, ext=nil, unit=nil)
	now.MoveRight(unit, count, ext)
end

#nowObject

返回Selection



93
94
95
# File 'lib/word_wps.rb', line 93

def now
	@word.Selection
end

#styles(name) ⇒ Object

风格设置



104
105
106
# File 'lib/word_wps.rb', line 104

def styles(name)
	@doc_work.Styles(name)
end

#update_catalogObject

更新目录



137
138
139
# File 'lib/word_wps.rb', line 137

def update_catalog
	word_basic.UpdateTableOfContents
end

#word_basicObject

自动化对象



61
62
63
# File 'lib/word_wps.rb', line 61

def word_basic
	doc_work.Application.WordBasic
end