xlsx.template xlsx.template

Help with Export Instruction

Export Instruction is how to write data from an active data record to specified cells in excel sheet. For example, an active record can be a sale order that user want to export. The record itself will be mapped to the header part of excel sheet. The record can contain multiple one2many fields, which will be written as data lines. You can look at following instruction as Excel Sheet(s), each with 1 header section (_HEAD_) and multiple row sections (one2many fields).

  • In header section part, map data fields (e.g., number, partner_id.name) into cells (e.g., B1, B2).
  • In row section, data list will be rolled out from one2many row field (e.g., order_line), and map data field (i.e., product_id.name, uom_id.name, qty) into the first row cells to start rolling (e.g., A6, B6, C6).

Following are more explaination on each column:

  • Sheet: Name (e.g., Sheet 1) or index (e.g., 1) of excel sheet to export data to
  • Row Field: Use _HEAD_ for the record itself, and one2many field (e.g., line_ids) for row data
  • Continue: If not selected, start rolling with specified first row cells. If selected, continue from previous one2many field
  • Cell: Location of data in excel sheet (e.g., A1, B1, ...)
  • Field: Field of the record, e.g., product_id.uom_id.name. They are orm compliant.
  • Field Cond.: Python code in ${...} to manipulate field value, e.g., if field = product_id, value will represent product object, e.g., ${value and value.uom_id.name or ""}
  • Sum: Add sum value on last row, @{sum}
  • Style: Default style in #{...} that apply to each cell, e.g., #{align=left;style=text}. See module's style.py for available styles.
  • Style w/Cond.: Conditional style by python code in #?...?, e.g., apply style for specific product, #?value.name == "ABC" and #{font=bold;fill=red} or None?

Note:

For code block ${...} and #?...?, following object are available,
  • value: value from Field
  • object: record object or line object depends on Row Field
  • model: active model, e.g., self.env['my.model']
  • date, datetime, time: some useful python classes

Help with Import Instruction

Import Instruction is how to get data from excel sheet and write them to an active record. For example, user create a sales order document, and want to import order lines from excel. In reverse direction to exporting, data from excel's cells will be mapped to record fields during import. Cells can be mapped to record in header section (_HEAD_) and data table can be mapped to row section (one2many field, begins from specifed cells.

  • In header section, map cells (e.g., B1, B2) into data fields (e.g., number, partner_id).
  • In row section, data table from excel can be imported to one2many row field (e.g., order_line) by mapping cells on first row onwards (e.g., A6, B6, C6) to fields (e.g., product_id, uom_id, qty)

Following are more explaination on each column:

  • Sheet: Name (e.g., Sheet 1) or index (e.g., 1) of excel sheet
  • Row Field: Use _HEAD_ for the record itself, and one2many field (e.g., line_ids) for row data
  • No Delete: By default, all one2many lines will be deleted before import. Select this, to avoid deletion
  • Cell: Location of data in excel sheet (e.g., A1, B1, ...)
  • Field: Field of the record to be imported to, e.g., product_id
  • Field Cond.: Python code in ${...} value will represent data from excel cell, e.g., if A1 = 'ABC', value will represent 'ABC', e.g., ${value == "ABC" and "X" or "Y"} thus can change from cell value to other value for import.

Note:

For code block ${...}, following object are available,
  • value: value from Cell
  • model: active model, e.g., self.env['my.model']
  • date, datetime, time: some useful python classes
XLSX Templates ir.actions.act_window xlsx.template form tree,form

Click to create a XLSX Template Object.