class Aio::Base::Toolkit::WordWps::Document

对文本控件的调用

Constants

Alignment
LineSpacingRule
NameAscii
NameFarEast
NameOther
NextParagraphStyle

Public Class Methods

new(document, word) click to toggle source
# 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

Public Instance Methods

add_table(row, col) click to toggle source

设置表格

# 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_text() click to toggle source

返回Text类

# 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) click to toggle source

将厘米换算成磅

# File lib/aio/base/toolkit/word_wps.rb, line 173
def cent_to_point(int)
  @word.CentimetersToPoints(int)
end
create_catalog() click to toggle source

创建目录

# 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_style() click to toggle source

创建样式

# 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| ... } click to toggle source

由实例自己创建风格

# 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_work() click to toggle source

ActiveDocument

# File lib/aio/base/toolkit/word_wps.rb, line 58
def doc_work
  @doc_work
end
end_key() click to toggle source

移动到行尾

# File lib/aio/base/toolkit/word_wps.rb, line 154
def end_key
  now.EndKey(5)
end
entry() click to toggle source

回车

# File lib/aio/base/toolkit/word_wps.rb, line 144
def entry
  now.TypeParagraph
end
home_key() click to toggle source

移动到行首

# File lib/aio/base/toolkit/word_wps.rb, line 149
def home_key
  now.HomeKey(5)
end
move_down() click to toggle source

移动到下一行

# 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) click to toggle source

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

# 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
now() click to toggle source

返回Selection

# File lib/aio/base/toolkit/word_wps.rb, line 95
def now
  @word.Selection
end
styles(name) click to toggle source

风格设置

# File lib/aio/base/toolkit/word_wps.rb, line 106
def styles(name)
  @doc_work.Styles(name)
end
update_catalog() click to toggle source

更新目录

# File lib/aio/base/toolkit/word_wps.rb, line 139
def update_catalog
  word_basic.UpdateTableOfContents
end
word_basic() click to toggle source

自动化对象

# File lib/aio/base/toolkit/word_wps.rb, line 63
def word_basic
  doc_work.Application.WordBasic
end