class PIM::MappingExporter::ExcelListExportDocument
Attributes
sheet_rows[R]
workbook[R]
Public Class Methods
matches?(mapping, template_asset)
click to toggle source
# File mapping-exporter.rb, line 139 def self.matches? mapping, template_asset mapping.template_type.to_s == 'LIST' && mapping.content_type == EXCEL_CONTENT_TYPE && template_asset.content_type == EXCEL_CONTENT_TYPE end
Public Instance Methods
create_workbook()
click to toggle source
# File mapping-exporter.rb, line 167 def create_workbook PIM.log_debug "creating workbook from template at #{template_asset}" open_xlsx_workbook(template_asset.path, template_asset.gathering_key) end
output_content_type()
click to toggle source
# File mapping-exporter.rb, line 143 def output_content_type EXCEL_CONTENT_TYPE end
start()
click to toggle source
# File mapping-exporter.rb, line 147 def start @workbook = create_workbook @sheet_rows = {} if PIM.is_empty?(mapping.template_sheets) @sheet_rows[0] = 1 else mapping.template_sheets.each do |sheet| @sheet_rows[sheet.name] = sheet.data_row end end end
stop()
click to toggle source
# File mapping-exporter.rb, line 162 def stop PIM.log_debug "saving workbook to output" save_workbook(workbook, output) end
write_mapped_item(mapped_item)
click to toggle source
# File mapping-exporter.rb, line 172 def write_mapped_item mapped_item sheets = Set.new mapped_item.mapped_values.each do |mapped_value| location = mapped_value[:location] sheet, column = split_location(location) # TODO: Check if it was possible to only use 'column' or 'external_name' to identify location! if PIM.is_empty?(column) external_name = mapped_value[:external_name] || '<not set>' PIM.log_debug "#{self.class}#write_mapped_item: column is empty for location #{location}, external_name: #{external_name}" next end sheet ||= 0 row = (sheet_rows[sheet] ||= 1) location = "#{column}#{row}" value = mapped_value[:mapped_value] PIM.log_debug "#{self.class}#write_mapped_item, sheet: #{sheet}, location: #{location}, value: #{value}, value.class: #{value.class}" begin set_cell_value_at workbook, sheet, "#{location}", value rescue Exception => e PIM.log_error("Could not set cell value '#{value}' at #{location}", e) end sheets.add(sheet) end # Goto next row sheets.each do |sheet| sheet_rows[sheet] += 1 end end