Class: Aio::Base::Toolkit::ExcelWps::WorkSheet
- Inherits:
-
Object
- Object
- Aio::Base::Toolkit::ExcelWps::WorkSheet
- Defined in:
- lib/aio/base/toolkit/excel_wps.rb
Overview
class WorkBook
Constant Summary collapse
- IMAGE_ROW_NUM =
56- @@worksheets_name =
[]
Instance Method Summary collapse
-
#add_chart(&block) ⇒ Object
添加图表.
-
#add_image(image_path) ⇒ Object
添加图像.
-
#add_row {|@current_row| ... } ⇒ Object
增加Row类.
-
#add_space_line(n = 1) ⇒ Object
增加一个空行.
-
#add_title(name) ⇒ Object
添加标题行.
-
#current_row ⇒ Object
返回此时的Row类.
-
#current_row_id ⇒ Object
返回此时的行索引.
-
#has_pagebreak? ⇒ Boolean
判断是否有垂直分页符存在.
- #height(height) ⇒ Object
-
#initialize(worksheet) ⇒ WorkSheet
constructor
A new instance of WorkSheet.
-
#merge(range1, range2) ⇒ Object
对列进行合并.
-
#pagebreak(col) ⇒ Object
对列修改分页符.
-
#range(str) ⇒ Object
产生 ::Range 类.
-
#width(col, width) ⇒ Object
设置列的宽度.
-
#worksheet ⇒ Object
返回::WorkSheet.
Constructor Details
#initialize(worksheet) ⇒ WorkSheet
Returns a new instance of WorkSheet.
101 102 103 104 105 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 101 def initialize(worksheet) @row_count = 1 @worksheet = worksheet @nil_space = [] end |
Instance Method Details
#add_chart(&block) ⇒ Object
添加图表
183 184 185 186 187 188 189 190 191 |
# 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) ⇒ Object
添加图像
157 158 159 160 161 162 163 164 165 |
# 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| ... } ⇒ Object
增加Row类
138 139 140 141 142 143 144 |
# 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) ⇒ Object
增加一个空行
108 109 110 111 |
# 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) ⇒ Object
添加标题行
124 125 126 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 124 def add_title(name) add_row.add_cell(name, false, "BoldStyle") end |
#current_row ⇒ Object
返回此时的Row类
147 148 149 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 147 def current_row return @current_row end |
#current_row_id ⇒ Object
返回此时的行索引
152 153 154 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 152 def current_row_id return @current_row.row_id end |
#has_pagebreak? ⇒ Boolean
判断是否有垂直分页符存在
168 169 170 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 168 def has_pagebreak? @worksheet.VPageBreaks.count > 0 end |
#height(height) ⇒ Object
133 134 135 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 133 def height(height) @row_height = height end |
#merge(range1, range2) ⇒ Object
对列进行合并
114 115 116 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 114 def merge(range1, range2) @worksheet.range("#{range1}:#{range2}").merge end |
#pagebreak(col) ⇒ Object
对列修改分页符
173 174 175 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 173 def pagebreak(col) @worksheet.VPageBreaks(1).Location = @worksheet.columns(col) end |
#range(str) ⇒ Object
产生 ::Range 类
119 120 121 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 119 def range(str) @worksheet.range(str) end |
#width(col, width) ⇒ Object
设置列的宽度
129 130 131 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 129 def width(col, width) @worksheet.Columns("#{col}:#{col}").ColumnWidth = width end |
#worksheet ⇒ Object
返回::WorkSheet
178 179 180 |
# File 'lib/aio/base/toolkit/excel_wps.rb', line 178 def worksheet @worksheet end |