class Aio::Base::Toolkit::ExcelWps::Row

Constants

FILL_TYPE
PageBreak
RowHeight
Style
Value
WrapText

Attributes

row_id[R]

Public Class Methods

new(worksheet, row_id) click to toggle source
# File lib/aio/base/toolkit/excel_wps.rb, line 200
def initialize(worksheet, row_id)
  @row_id = row_id
  @cell_count = 0
  @worksheet = worksheet
  @nil_space = []
end

Public Instance Methods

<<(arr) click to toggle source

特别注意,由于Toolkit中加入了Array,String的模块 所以判断的时候特别注意要是

# File lib/aio/base/toolkit/excel_wps.rb, line 245
def <<(arr)
  case arr
  when ::Array
    arr.size.times do |t|
      add_cell(arr[t])
    end
  when ::String
    add_cell(arr)
  end
end
add_cell(value, auto_fit = false, style = "NormalStyle") click to toggle source

增加单元格

# File lib/aio/base/toolkit/excel_wps.rb, line 223
def add_cell(value, auto_fit = false, style = "NormalStyle")
  range = @worksheet.Range(cell_name(@cell_count))
  range.Value = value.to_s
  range.Style = style
  range.Columns.AutoFit if auto_fit
  @cell_count += 1
  while(@nil_space.include?(to_letter(@cell_count))) do 
    range = @worksheet.Range(cell_name(@cell_count))
    range.Value = ""
    range.Style = style
    @cell_count += 1
  end

end
cell_name(index) click to toggle source

获得单元格的名字(通过索引)

# File lib/aio/base/toolkit/excel_wps.rb, line 257
def cell_name(index)
  second = index % 26
  first = (index - second) / 26
  if first == 0
    return @@cell_map[second] + @row_id.to_s
  end
  first -= 1
  return @@cell_map[first] + @@cell_map[second] + @row_id.to_s
end
cell_name!(letter) click to toggle source

获得单元格的名字(通过字母)

# File lib/aio/base/toolkit/excel_wps.rb, line 268
def cell_name!(letter)
  return letter + @row_id.to_s
end
curent_cell() click to toggle source

此时的单元格

# File lib/aio/base/toolkit/excel_wps.rb, line 208
def curent_cell
  return cell_name(@cell_count)
end
first_cell() click to toggle source

第一个单元格

# File lib/aio/base/toolkit/excel_wps.rb, line 213
def first_cell
  return cell_name(0)
end
height=(height) click to toggle source

设置行高

# File lib/aio/base/toolkit/excel_wps.rb, line 218
def height=(height)
  @worksheet.rows(@row_id).RowHeight = height
end
merge(idx_begin, idx_end) click to toggle source

合并一行中的单元格

# File lib/aio/base/toolkit/excel_wps.rb, line 286
def merge(idx_begin, idx_end)
  cell_begin = "#{idx_begin}#{@row_id}"
  cell_end = "#{idx_end}#{@row_id}"
  range = @worksheet.Range("#{cell_begin}:#{cell_end}")
  range.merge
  tmp = ((idx_begin.upcase)..(idx_end.upcase)).to_a
  tmp.shift
  @nil_space = (@nil_space | tmp).sort
end
pagebreak() click to toggle source

对此时的行的下方下分页符

# File lib/aio/base/toolkit/excel_wps.rb, line 303
def pagebreak
  @worksheet.rows(@row_id+1).PageBreak = 1
end
real_row() click to toggle source

返回此时的::Row类

# File lib/aio/base/toolkit/excel_wps.rb, line 308
def real_row
  @worksheet.rows(@row_id)
end
set_cell(index, value, auto_fit = false, style = "NormalStyle") click to toggle source
# File lib/aio/base/toolkit/excel_wps.rb, line 272
def set_cell(index, value, auto_fit = false, style = "NormalStyle")
  range = @worksheet.Range(cell_name(index))
  range.Value = value.to_s
  range.Style = style
  range.Columns.AutoFit if auto_fit
end
set_style(letter, style = "NormalStyle") click to toggle source

设置单元格风格

# File lib/aio/base/toolkit/excel_wps.rb, line 280
def set_style(letter, style = "NormalStyle")
  range = @worksheet.range(cell_name!(letter))
  range.Style = style
end
Also aliased as: style
style(letter, style = "NormalStyle")
Alias for: set_style
to_letter(index) click to toggle source

通过索引变成对应的字母

# File lib/aio/base/toolkit/excel_wps.rb, line 239
def to_letter(index)
  @@cell_map.at(index)
end
wraptext(letter) click to toggle source

开启自动换行

# File lib/aio/base/toolkit/excel_wps.rb, line 297
def wraptext(letter)
  range = @worksheet.range(cell_name!(letter))
  range.WrapText = true
end