How to use the xlsxwriter.utility.xl_col_to_name function in XlsxWriter

To help you get started, we’ve selected a few XlsxWriter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pjamesjoyce / lcopt / lcopt / interact.py View on Github external
worksheet.write(i + row_offset + 1, j + col_offset + 2, results[j]['scores'][i], cell_format)

        for i, m in enumerate(method_names):
            worksheet.write(i + row_offset + 1, col_offset, m, row_header_format)
            worksheet.write(i + row_offset + 1, col_offset + 1, settings['method_units'][i], row_header_format)

        for j, p in enumerate(ps_names):
            worksheet.write(row_offset, j + col_offset + 2, p, col_header_format)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(0), xlsxwriter.utility.xl_col_to_name(0)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 5)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset), xlsxwriter.utility.xl_col_to_name(col_offset)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 25)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset + 1), xlsxwriter.utility.xl_col_to_name(col_offset + 1 + len(ps_names))
        worksheet.set_column('{}:{}'.format(start_col, end_col), 12)

        workbook.close()

        #go back to the beginning of the stream
        output.seek(0)
        
        return output
github pjamesjoyce / lcopt / lcopt / interact.py View on Github external
for i, m in enumerate(method_names):
            for j, p in enumerate(ps_names):
                worksheet.write(i + row_offset + 1, j + col_offset + 2, results[j]['scores'][i], cell_format)

        for i, m in enumerate(method_names):
            worksheet.write(i + row_offset + 1, col_offset, m, row_header_format)
            worksheet.write(i + row_offset + 1, col_offset + 1, settings['method_units'][i], row_header_format)

        for j, p in enumerate(ps_names):
            worksheet.write(row_offset, j + col_offset + 2, p, col_header_format)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(0), xlsxwriter.utility.xl_col_to_name(0)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 5)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset), xlsxwriter.utility.xl_col_to_name(col_offset)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 25)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset + 1), xlsxwriter.utility.xl_col_to_name(col_offset + 1 + len(ps_names))
        worksheet.set_column('{}:{}'.format(start_col, end_col), 12)

        workbook.close()

        #go back to the beginning of the stream
        output.seek(0)
        
        return output
github magma / magma / symphony / cli / pyworkforce / api / site_survey.py View on Github external
def write_column_titles(
    worksheet: Worksheet,
    num_columns: int,
    title_format: Format,
    translations: Dict[str, str],
) -> None:
    worksheet.write("A1", translations.get("Form", "Form"), title_format)
    for i in range(1, num_columns - 1):
        worksheet.write_blank(f"{xl_col_to_name(i)}1", "", title_format)
    worksheet.write(
        f"{xl_col_to_name(num_columns - 1)}1",
        translations.get("Question", "Question"),
        title_format,
    )
    worksheet.write(
        f"{xl_col_to_name(num_columns)}1",
        translations.get("Answer", "Answer"),
        title_format,
    )
github getredash / redash / redash / query_runner / google_spreadsheets.py View on Github external
def _get_columns_and_column_names(row):
    column_names = []
    columns = []
    duplicate_counter = 1

    for i, column_name in enumerate(row):
        if not column_name:
            column_name = 'column_{}'.format(xl_col_to_name(i))

        if column_name in column_names:
            column_name = "{}{}".format(column_name, duplicate_counter)
            duplicate_counter += 1

        column_names.append(column_name)
        columns.append({
            'name': column_name,
            'friendly_name': column_name,
            'type': TYPE_STRING
        })

    return columns, column_names
github Code4SA / mma-dexter / dexter / analysis / ratings.py View on Github external
def add_nested_ratings(self, ratings, row, col):
        rating_rows = []

        for info in ratings:
            weight, rating = info[0:2]

            rating_rows.append(row)
            self.rating_ws.write(row, col, weight)
            self.rating_ws.write(row, col + 1, rating)

            if len(info) > 2:
                # add sub-ratings
                rows, last_row = self.add_nested_ratings(info[2], row + 1, col + 1)

                # now set this rating's score to the product of the children
                col_name = xl_col_to_name(col + 1)
                for i in xrange(self.n_columns):
                    rating_col_name = xl_col_to_name(self.rating_col(i))
                    # weight * score
                    formula = '+'.join('%s%s*%s%s' % (col_name, r + 1, rating_col_name, r + 1) for r in rows)
                    self.rating_ws.write_formula(row, self.rating_col(i), formula)

                row = last_row
            else:
                # actual rating
                score_row = self.score_row[rating]

                for i in xrange(self.n_columns):
                    cell = xl_rowcol_to_cell(score_row, self.score_col(i), row_abs=True, col_abs=True)
                    self.rating_ws.write(row, self.rating_col(i), '=Raw!%s' % cell)
            row += 1
github pjamesjoyce / lcopt / lcopt / interact.py View on Github external
worksheet.write(row_offset, col_offset + i + 1, p, col_header_format)
            worksheet.write(row_offset + 1, col_offset + i + 1, results[i]['scores'][m], total_format)

        for i, item in enumerate(table_data[0]):
            worksheet.write(row_offset + i + 2, col_offset, item['name'], row_header_format)

        no_items = len(table_data[0])

        for i, item in enumerate(table_data):
            for j in range(no_items):
                worksheet.write(row_offset + j + 2, col_offset + i + 1, item[j]['value'], cell_format)
        
        start_col, end_col = xlsxwriter.utility.xl_col_to_name(0), xlsxwriter.utility.xl_col_to_name(0)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 5)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset), xlsxwriter.utility.xl_col_to_name(col_offset)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 25)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset + 1), xlsxwriter.utility.xl_col_to_name(col_offset + len(ps_names))
        worksheet.set_column('{}:{}'.format(start_col, end_col), 12)

        workbook.close()
        output.seek(0)

        return output
github SaturnFromTitan / adwords_reports / freedan / other_services / drive.py View on Github external
def a1_notation(values, sheet_name):
        """ Get A1 notation associated with the size of values
        :param values: list of lists representing 2d array
        :param sheet_name: Google Drive sheet name
        :return: str, representing the range of AdWords
        """
        assert isinstance(values, list)
        assert isinstance(values[0], list)
        num_cols = len(values[0])
        col_name = xl_col_to_name(num_cols-1)
        return "{sheet_name}!A1:{col}".format(sheet_name=sheet_name, col=col_name)
github pjamesjoyce / lcopt / lcopt / interact.py View on Github external
worksheet.write(row_offset + 1, col_offset, 'Total', total_format)

        for i, p in enumerate(ps_names):
            worksheet.write(row_offset, col_offset + i + 1, p, col_header_format)
            worksheet.write(row_offset + 1, col_offset + i + 1, results[i]['scores'][m], total_format)

        for i, item in enumerate(table_data[0]):
            worksheet.write(row_offset + i + 2, col_offset, item['name'], row_header_format)

        no_items = len(table_data[0])

        for i, item in enumerate(table_data):
            for j in range(no_items):
                worksheet.write(row_offset + j + 2, col_offset + i + 1, item[j]['value'], cell_format)
        
        start_col, end_col = xlsxwriter.utility.xl_col_to_name(0), xlsxwriter.utility.xl_col_to_name(0)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 5)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset), xlsxwriter.utility.xl_col_to_name(col_offset)
        worksheet.set_column('{}:{}'.format(start_col, end_col), 25)

        start_col, end_col = xlsxwriter.utility.xl_col_to_name(col_offset + 1), xlsxwriter.utility.xl_col_to_name(col_offset + len(ps_names))
        worksheet.set_column('{}:{}'.format(start_col, end_col), 12)

        workbook.close()
        output.seek(0)

        return output
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
def _convert_name_area(self, row_num_1, col_num_1, row_num_2, col_num_2):
        # Convert zero indexed rows and columns to the format required by
        # worksheet named ranges, eg, "Sheet1!$A$1:$C$13".

        range1 = ''
        range2 = ''
        area = ''
        row_col_only = 0

        # Convert to A1 notation.
        col_char_1 = xl_col_to_name(col_num_1, 1)
        col_char_2 = xl_col_to_name(col_num_2, 1)
        row_char_1 = '$' + str(row_num_1 + 1)
        row_char_2 = '$' + str(row_num_2 + 1)

        # We need to handle special cases that refer to rows or columns only.
        if row_num_1 == 0 and row_num_2 == self.xls_rowmax - 1:
            range1 = col_char_1
            range2 = col_char_2
            row_col_only = 1
        elif col_num_1 == 0 and col_num_2 == self.xls_colmax - 1:
            range1 = row_char_1
            range2 = row_char_2
            row_col_only = 1
        else:
            range1 = col_char_1 + row_char_1
            range2 = col_char_2 + row_char_2