(self, export_instances)
Open the _Writer for writing. This must be called before using _Writer.write().
        Note that this function returns a context manager!
        A _Writer can only be opened once.
Open the _Writer for writing. This must be called before using _Writer.write().
        Note that this function returns a context manager!
        A _Writer can only be opened once.
Open the _Writer for writing . This must be called before using _Writer . write () . Note that this function returns a context manager! A _Writer can only be opened once .
def open(self, export_instances):
        """
        Open the _Writer for writing. This must be called before using _Writer.write().
        Note that this function returns a context manager!
        A _Writer can only be opened once.
        """

        if len(export_instances) == 1:
            name = export_instances[0].name or ''
        else:
            name = ''
        name = safe_filename(name)
        all_sheet_names = Counter(
            table.label for instance in export_instances for table in instance.selected_tables
        )

        with open(self.path, 'wb') as file:

            # open the ExportWriter
            headers = []
            table_titles = {}
            for instance_index, instance in enumerate(export_instances):
                headers += [
                    (t, (t.get_headers(split_columns=instance.split_multiselects),))
                    for t in instance.selected_tables
                ]
                for table_index, table in enumerate(instance.selected_tables):
                    sheet_name = table.label or "Sheet{}".format(table_index + 1)
                    # If it's a bulk export and the sheet has the same name as another sheet,
                    # Prefix the sheet name with the export name
                    if len(export_instances) > 1 and all_sheet_names[sheet_name] > 1:
                        sheet_name = "{}-{}".format(
                            instance.name or "Export{}".format(instance_index + 1),
                            sheet_name
                        )
                    table_titles[table] = sheet_name
            self.writer.open(headers, file, table_titles=table_titles, archive_basepath=name)
            try:
                yield
            finally:
                self.writer.close()
def open ( self , export_instances ) : if len ( export_instances ) == 1 : name = export_instances [ 0 ] . name or '' else : name = '' name = safe_filename ( name ) all_sheet_names = Counter ( table . label for instance in export_instances for table in instance . selected_tables ) with open ( self . path , 'wb' ) as file : # open the ExportWriter headers = [ ] table_titles = { } for instance_index , instance in enumerate ( export_instances ) : headers += [ ( t , ( t . get_headers ( split_columns = instance . split_multiselects ) , ) ) for t in instance . selected_tables ] for table_index , table in enumerate ( instance . selected_tables ) : sheet_name = table . label or "Sheet{}" . format ( table_index + 1 ) # If it's a bulk export and the sheet has the same name as another sheet, # Prefix the sheet name with the export name if len ( export_instances ) > 1 and all_sheet_names [ sheet_name ] > 1 : sheet_name = "{}-{}" . format ( instance . name or "Export{}" . format ( instance_index + 1 ) , sheet_name ) table_titles [ table ] = sheet_name self . writer . open ( headers , file , table_titles = table_titles , archive_basepath = name ) try : yield finally : self . writer . close ( )