Class: XlsxKit::Workbook::SheetRowHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsxkit/workbook.rb

Overview


Sheet Row SAX Handler

解析 下的 → → / 结构, 将每行的单元格值提取为数组,逐行收集。

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shared_strings) ⇒ SheetRowHandler

Returns a new instance of SheetRowHandler.



326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/xlsxkit/workbook.rb', line 326

def initialize(shared_strings)
  @sst = shared_strings
  @rows = []
  @in_row = false
  @in_cell = false
  @in_v = false
  @in_is = false
  @in_is_t = false
  @cell_type = nil
  @cell_ref = nil
  @chars = nil
  @current_row = nil
end

Instance Attribute Details

#rows ⇒ Object (readonly)

Returns the value of attribute rows.



324
325
326
# File 'lib/xlsxkit/workbook.rb', line 324

def rows
  @rows
end

Instance Method Details

#characters(text) ⇒ Object



359
360
361
# File 'lib/xlsxkit/workbook.rb', line 359

def characters(text)
  @chars << text if @in_cell && (@in_v || (@in_is && @in_is_t))
end

#end_element(name) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/xlsxkit/workbook.rb', line 363

def end_element(name)
  case name
  when 'row'
    @rows << @current_row
    @in_row = false
    @current_row = nil
  when 'c'
    val = resolve_cell_value
    if @cell_ref
      col = col_ref_to_index(@cell_ref)
      @current_row.fill(nil, @current_row.length...col) if col > @current_row.length
      @current_row[col] = val
    else
      @current_row << val
    end
    @in_cell = false
    @cell_type = nil
    @cell_ref = nil
    @chars = nil
  when 'v'
    @in_v = false
  when 'is'
    @in_is = false
  when 't'
    @in_is_t = false if @in_is
  end
end

#start_element(name, attrs) ⇒ Object



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/xlsxkit/workbook.rb', line 340

def start_element(name, attrs)
  case name
  when 'row'
    @in_row = true
    @current_row = []
  when 'c'
    @in_cell = true
    @cell_type = attrs['t']
    @cell_ref = attrs['r']
    @chars = +''
  when 'v'
    @in_v = true
  when 'is'
    @in_is = true
  when 't'
    @in_is_t = true if @in_is
  end
end