Class: Aio::Base::Toolkit::ExcelOffice::WorkSheet
- Inherits:
-
Object
- Object
- Aio::Base::Toolkit::ExcelOffice::WorkSheet
- Defined in:
- lib/aio/base/toolkit/excel_office.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_left(num) ⇒ Object
对列修改分页符.
-
#range(str) ⇒ Object
产生 ::Range 类.
-
#width(col, width) ⇒ Object
设置列的宽度.
-
#worksheet ⇒ Object
返回::WorkSheet.
Constructor Details
#initialize(worksheet) ⇒ WorkSheet
Returns a new instance of WorkSheet.
96 97 98 99 100 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 96 def initialize(worksheet) @row_count = 1 @worksheet = worksheet @nil_space = [] end |
Instance Method Details
#add_chart(&block) ⇒ Object
添加图表
185 186 187 188 189 190 191 192 193 |
# 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) ⇒ Object
添加图像
158 159 160 161 162 163 164 165 166 |
# 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| ... } ⇒ Object
增加Row类
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# 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) ⇒ Object
增加一个空行
103 104 105 106 |
# 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) ⇒ Object
添加标题行
119 120 121 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 119 def add_title(name) add_row.add_cell(name, false, "BoldStyle") end |
#current_row ⇒ Object
返回此时的Row类
148 149 150 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 148 def current_row return @current_row end |
#current_row_id ⇒ Object
返回此时的行索引
153 154 155 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 153 def current_row_id return @current_row.row_id end |
#has_pagebreak? ⇒ Boolean
判断是否有垂直分页符存在
169 170 171 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 169 def has_pagebreak? @worksheet.VPageBreaks.count > 0 end |
#height(height) ⇒ Object
128 129 130 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 128 def height(height) @row_height = height end |
#merge(range1, range2) ⇒ Object
对列进行合并
109 110 111 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 109 def merge(range1, range2) @worksheet.range("#{range1}:#{range2}").merge end |
#pagebreak_left(num) ⇒ Object
对列修改分页符
174 175 176 177 |
# 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) ⇒ Object
产生 ::Range 类
114 115 116 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 114 def range(str) @worksheet.range(str) end |
#width(col, width) ⇒ Object
设置列的宽度
124 125 126 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 124 def width(col, width) @worksheet.Columns("#{col}:#{col}").ColumnWidth = width end |
#worksheet ⇒ Object
返回::WorkSheet
180 181 182 |
# File 'lib/aio/base/toolkit/excel_office.rb', line 180 def worksheet @worksheet end |