class Aio::Base::Toolkit::ExcelWps::WorkSheet

Constants

ColumnWidth
IMAGE_ROW_NUM
Location

Public Class Methods

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

Public Instance Methods

add_chart(&block) click to toggle source

添加图表

# File lib/aio/base/toolkit/excel_wps.rb, line 183
def add_chart(&block)
  ch = @worksheet.Shapes.AddChart
  active = ch.chart

  # 占位符
  block.call(Chart.new(active))

  ch.copy
end
add_image(image_path) click to toggle source

添加图像

# File lib/aio/base/toolkit/excel_wps.rb, line 157
def add_image(image_path)
  return unless File.exist?(image_path)
  add_space_line
  add_row
  cell_name = current_row.first_cell
  @worksheet.Range(cell_name).Select
  @worksheet.Pictures.Insert(image_path)
  add_space_line IMAGE_ROW_NUM
end
add_row() { |current_row| ... } click to toggle source

增加Row类

# File lib/aio/base/toolkit/excel_wps.rb, line 138
def add_row(&block)
  @current_row = Row.new(@worksheet, @row_count)
  @current_row.height = @row_height if @row_height
  @row_count += 1
  yield @current_row if block
  return @current_row
end
add_space_line(n=1) click to toggle source

增加一个空行

# File lib/aio/base/toolkit/excel_wps.rb, line 108
def add_space_line(n=1)
  return if n < 1
  @row_count += n
end
add_title(name) click to toggle source

添加标题行

# File lib/aio/base/toolkit/excel_wps.rb, line 124
def add_title(name)
  add_row.add_cell(name, false, "BoldStyle")
end
current_row() click to toggle source

返回此时的Row类

# File lib/aio/base/toolkit/excel_wps.rb, line 147
def current_row
  return @current_row
end
current_row_id() click to toggle source

返回此时的行索引

# File lib/aio/base/toolkit/excel_wps.rb, line 152
def current_row_id
  return @current_row.row_id
end
has_pagebreak?() click to toggle source

判断是否有垂直分页符存在

# File lib/aio/base/toolkit/excel_wps.rb, line 168
def has_pagebreak?
  @worksheet.VPageBreaks.count > 0 
end
height(height) click to toggle source
# File lib/aio/base/toolkit/excel_wps.rb, line 133
def height(height)
  @row_height = height
end
merge(range1, range2) click to toggle source

对列进行合并

# File lib/aio/base/toolkit/excel_wps.rb, line 114
def merge(range1, range2)
  @worksheet.range("#{range1}:#{range2}").merge
end
pagebreak(col) click to toggle source

对列修改分页符

# File lib/aio/base/toolkit/excel_wps.rb, line 173
def pagebreak(col)
  @worksheet.VPageBreaks(1).Location = @worksheet.columns(col)
end
range(str) click to toggle source

产生 ::Range 类

# File lib/aio/base/toolkit/excel_wps.rb, line 119
def range(str)
  @worksheet.range(str)
end
width(col, width) click to toggle source

设置列的宽度

# File lib/aio/base/toolkit/excel_wps.rb, line 129
def width(col, width)
  @worksheet.Columns("#{col}:#{col}").ColumnWidth = width
end
worksheet() click to toggle source

返回::WorkSheet

# File lib/aio/base/toolkit/excel_wps.rb, line 178
def worksheet
  @worksheet
end