class Aio::Base::Toolkit::ExcelOffice::WorkSheet
Constants
- ColumnWidth
- IMAGE_ROW_NUM
Public Class Methods
new(worksheet)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 96 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_office.rb, line 185 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_office.rb, line 158 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_office.rb, line 133 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 @current_row.merge! begin @current_row.real_row.borders.linestyle = 1 rescue Exception retry end return @current_row end
add_space_line(n=1)
click to toggle source
增加一个空行
# File lib/aio/base/toolkit/excel_office.rb, line 103 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_office.rb, line 119 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_office.rb, line 148 def current_row return @current_row end
current_row_id()
click to toggle source
返回此时的行索引
# File lib/aio/base/toolkit/excel_office.rb, line 153 def current_row_id return @current_row.row_id end
has_pagebreak?()
click to toggle source
判断是否有垂直分页符存在
# File lib/aio/base/toolkit/excel_office.rb, line 169 def has_pagebreak? @worksheet.VPageBreaks.count > 0 end
height(height)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 128 def height(height) @row_height = height end
merge(range1, range2)
click to toggle source
对列进行合并
# File lib/aio/base/toolkit/excel_office.rb, line 109 def merge(range1, range2) @worksheet.range("#{range1}:#{range2}").merge end
pagebreak_left(num)
click to toggle source
对列修改分页符
# File lib/aio/base/toolkit/excel_office.rb, line 174 def pagebreak_left(num) #@worksheet.VPageBreaks(1).Location = @worksheet.columns(col) @worksheet.VPageBreaks(1).DragOff("-4161", num.to_i) end
range(str)
click to toggle source
产生 ::Range 类
# File lib/aio/base/toolkit/excel_office.rb, line 114 def range(str) @worksheet.range(str) end
width(col, width)
click to toggle source
设置列的宽度
# File lib/aio/base/toolkit/excel_office.rb, line 124 def width(col, width) @worksheet.Columns("#{col}:#{col}").ColumnWidth = width end
worksheet()
click to toggle source
返回::WorkSheet
# File lib/aio/base/toolkit/excel_office.rb, line 180 def worksheet @worksheet end