class ExcelWps::WorkSheet
Constants
- ColumnWidth
- IMAGE_ROW_NUM
- Location
Public Class Methods
new(worksheet)
click to toggle source
# File lib/excel_wps.rb, line 99 def initialize(worksheet) @row_count = 1 @worksheet = worksheet @nil_space = [] end
Public Instance Methods
add_chart(&block)
click to toggle source
添加图表
# File lib/excel_wps.rb, line 181 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/excel_wps.rb, line 155 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/excel_wps.rb, line 136 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/excel_wps.rb, line 106 def add_space_line(n=1) return if n < 1 @row_count += n end
add_title(name)
click to toggle source
添加标题行
# File lib/excel_wps.rb, line 122 def add_title(name) add_row.add_cell(name, false, "BoldStyle") end
current_row()
click to toggle source
返回此时的Row类
# File lib/excel_wps.rb, line 145 def current_row return @current_row end
current_row_id()
click to toggle source
返回此时的行索引
# File lib/excel_wps.rb, line 150 def current_row_id return @current_row.row_id end
has_pagebreak?()
click to toggle source
判断是否有垂直分页符存在
# File lib/excel_wps.rb, line 166 def has_pagebreak? @worksheet.VPageBreaks.count > 0 end
height(height)
click to toggle source
# File lib/excel_wps.rb, line 131 def height(height) @row_height = height end
merge(range1, range2)
click to toggle source
对列进行合并
# File lib/excel_wps.rb, line 112 def merge(range1, range2) @worksheet.range("#{range1}:#{range2}").merge end
pagebreak(col)
click to toggle source
对列修改分页符
# File lib/excel_wps.rb, line 171 def pagebreak(col) @worksheet.VPageBreaks(1).Location = @worksheet.columns(col) end
range(str)
click to toggle source
产生 ::Range 类
# File lib/excel_wps.rb, line 117 def range(str) @worksheet.range(str) end
width(col, width)
click to toggle source
设置列的宽度
# File lib/excel_wps.rb, line 127 def width(col, width) @worksheet.Columns("#{col}:#{col}").ColumnWidth = width end
worksheet()
click to toggle source
返回::WorkSheet
# File lib/excel_wps.rb, line 176 def worksheet @worksheet end