Class: Aio::Base::Toolkit::WordWps::Document

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

Overview

对文本控件的调用

Instance Method Summary collapse

Constructor Details

#initialize(document, word) ⇒ Document

Returns a new instance of Document.



50
51
52
53
54
55
# File 'lib/aio/base/toolkit/word_wps.rb', line 50

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

设置表格



111
112
113
# File 'lib/aio/base/toolkit/word_wps.rb', line 111

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

#add_textObject

返回Text类



100
101
102
103
# File 'lib/aio/base/toolkit/word_wps.rb', line 100

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

#cent_to_point(int) ⇒ Object

将厘米换算成磅



173
174
175
# File 'lib/aio/base/toolkit/word_wps.rb', line 173

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

#create_catalogObject

创建目录



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

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

创建样式



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/aio/base/toolkit/word_wps.rb', line 68

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)


89
90
91
92
# File 'lib/aio/base/toolkit/word_wps.rb', line 89

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

#doc_workObject

ActiveDocument



58
59
60
# File 'lib/aio/base/toolkit/word_wps.rb', line 58

def doc_work
  @doc_work
end

#end_keyObject

移动到行尾



154
155
156
# File 'lib/aio/base/toolkit/word_wps.rb', line 154

def end_key
  now.EndKey(5)
end

#entryObject

回车



144
145
146
# File 'lib/aio/base/toolkit/word_wps.rb', line 144

def entry
  now.TypeParagraph
end

#home_keyObject

移动到行首



149
150
151
# File 'lib/aio/base/toolkit/word_wps.rb', line 149

def home_key
  now.HomeKey(5)
end

#move_downObject

移动到下一行



159
160
161
162
# File 'lib/aio/base/toolkit/word_wps.rb', line 159

def move_down
  self.end_key
  self.entry
end

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

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



168
169
170
# File 'lib/aio/base/toolkit/word_wps.rb', line 168

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

#nowObject

返回Selection



95
96
97
# File 'lib/aio/base/toolkit/word_wps.rb', line 95

def now
  @word.Selection
end

#styles(name) ⇒ Object

风格设置



106
107
108
# File 'lib/aio/base/toolkit/word_wps.rb', line 106

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

#update_catalogObject

更新目录



139
140
141
# File 'lib/aio/base/toolkit/word_wps.rb', line 139

def update_catalog
  word_basic.UpdateTableOfContents
end

#word_basicObject

自动化对象



63
64
65
# File 'lib/aio/base/toolkit/word_wps.rb', line 63

def word_basic
  doc_work.Application.WordBasic
end