示例#1
0
 def parse_workbook(wb):
     mapping = DATASHEET_META_MAPPING
     meta_ws = util_xls.get_sheet(wb, mapping.sheet_name)
     if meta_ws is None:
         raise NoMetaDataSheetException("Meta sheet not found.")
     key = util_model.get_field_verbose_name(Visit, 'name')
     reading_direction = 'right' if mapping.transpose else 'down'
     visit_name = util_xls.get_value_for_key(meta_ws, key, direction=reading_direction)
     key = util_model.get_field_verbose_name(Site, 'site_code')
     site_code = util_xls.get_value_for_key(meta_ws, key, direction=reading_direction)
     return MetaData(visit_name, site_code)
示例#2
0
 def _create_meta(self, visit_name, site_code):
     # TODO: use the download.utils.SiteVisitDatasheetWriter to write the metadata
     wb = Workbook()
     mapping = DATASHEET_META_MAPPING
     meta_ws = wb.active
     # rewrite the sheet name in case of the 'Sheet' selection.
     meta_ws.title = mapping.sheet_name
     col_headers = [util_model.get_field_verbose_name(Visit, 'name'),
                    util_model.get_field_verbose_name(Site, 'site_code')]
     # write column headers
     top_cell = meta_ws.cell(row=mapping.top_left_row, column=mapping.top_left_column)
     writing_direction = mapping.next_col_direction
     util_xls.write_values_from_cell(top_cell, col_headers, writing_direction)
     # write values
     values = [visit_name, site_code]
     top_cell = util_xls.get_cell_neighbour(top_cell, mapping.next_row_direction)
     util_xls.write_values_from_cell(top_cell, values, writing_direction)
     return wb
示例#3
0
文件: utils.py 项目: ropable/biosys
 def _write_meta(self):
     mapping = DATASHEET_META_MAPPING
     meta_ws = util_xls.get_sheet(self.wb, mapping.sheet_name) or util_xls.get_sheet(self.wb, 'Sheet')
     # rewrite the sheet name in case of the 'Sheet' selection.
     meta_ws.title = mapping.sheet_name
     if meta_ws is None:
         meta_ws = self.wb.create_sheet(0, mapping.sheet_name)
     # write the visit name
     # populate Meta with visit/site details (very rough)
     col_headers = [util_model.get_field_verbose_name(Visit, 'name'),
                    util_model.get_field_verbose_name(Site, 'site_code')]
     # write column headers
     top_cell = meta_ws.cell(row=mapping.top_left_row, column=mapping.top_left_column)
     writing_direction = mapping.next_col_direction
     util_xls.write_values_from_cell(top_cell, col_headers, writing_direction, self.column_header_font)
     # write values
     if self.visit and self.site:
         values = [self.visit.name, self.site.site_code]
         top_cell = util_xls.get_cell_neighbour(top_cell, mapping.next_row_direction)
         util_xls.write_values_from_cell(top_cell, values, writing_direction)
     return meta_ws