How to use XlsxWriter - 10 common examples

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 trailofbits / cb-multios / tools / tester.py View on Github external
def write_formula(row, col_name, formula, formula_col1, formula_col2, fmt=fmt_default):
        # type: (int, str, str, str, str, xl.format.Format) -> None
        ws.write_formula(row, col_to_idx[col_name],
                         formula.format(xlutil.xl_rowcol_to_cell(row, col_to_idx[formula_col1]),
                                        xlutil.xl_rowcol_to_cell(row, col_to_idx[formula_col2])), fmt)
github iotivity / iotivity / test / test_manager / ite / reporter / tc_reporter.py View on Github external
def report_to_xlsx(self, path):
        workbook = Workbook(path)
        form = ExcelFormat(workbook)

        summarysheet = workbook.add_worksheet('Summary')

        row = 0
        col = 0

        col += 1
        print (TEST_PLATFORM + ('Total',))
        for platform in TEST_PLATFORM + ('Total',):
            start_platfom_col = col

            for tctype in TESTCASE_TYPES + ('API TC',):
                summarysheet.write(row + 1, col, tctype, form.title)
                col += 1
github iotivity / iotivity / test / test_manager / ite / reporter / result_reporter.py View on Github external
def report_to_xlsx(self, path):
        workbook = Workbook(path)
        form = ExcelFormat(workbook)

        summarysheet = workbook.add_worksheet('Summary')

        row = 0
        col = 0

        summarysheet.merge_range(row, col, row+3, col, '', form.cell)

        col += 1
        for platform in TEST_PLATFORM:
            if not platform in self.summary:
                continue

            row += 1
            platform_col = col
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
def column_wrapper(self, *args):

        try:
            # First arg is an int, default to row/col notation.
            int(args[0])
            return method(self, *args)
        except ValueError:
            # First arg isn't an int, convert to A1 notation.
            cell_1, cell_2 = [col + '1' for col in args[0].split(':')]
            _, col_1 = xl_cell_to_rowcol(cell_1)
            _, col_2 = xl_cell_to_rowcol(cell_2)
            new_args = [col_1, col_2]
            new_args.extend(args[1:])
            return method(self, *new_args)
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
def column_wrapper(self, *args):

        try:
            # First arg is an int, default to row/col notation.
            int(args[0])
            return method(self, *args)
        except ValueError:
            # First arg isn't an int, convert to A1 notation.
            cell_1, cell_2 = [col + '1' for col in args[0].split(':')]
            _, col_1 = xl_cell_to_rowcol(cell_1)
            _, col_2 = xl_cell_to_rowcol(cell_2)
            new_args = [col_1, col_2]
            new_args.extend(args[1:])
            return method(self, *new_args)
github jmcnamara / XlsxWriter / xlsxwriter / workbook.py View on Github external
# Split the cell range into 2 cells or else use single cell for both.
        if cells.find(':') > 0:
            (cell_1, cell_2) = cells.split(':', 1)
        else:
            (cell_1, cell_2) = (cells, cells)

        # Remove leading/trailing quotes and convert escaped quotes to single.
        sheetname = sheetname.strip("'")
        sheetname = sheetname.replace("''", "'")

        try:
            # Get the row, col values from the Excel ranges. We do this in a
            # try block for ranges that can't be parsed such as defined names.
            (row_start, col_start) = xl_cell_to_rowcol(cell_1)
            (row_end, col_end) = xl_cell_to_rowcol(cell_2)
        except AttributeError:
            return None, None

        # We only handle 1D ranges.
        if row_start != row_end and col_start != col_end:
            return None, None

        return sheetname, [row_start, col_start, row_end, col_end]
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
def cell_wrapper(self, *args):

        try:
            # First arg is an int, default to row/col notation.
            int(args[0])
            return method(self, *args)
        except ValueError:
            # First arg isn't an int, convert to A1 notation.
            cell_1, cell_2 = args[0].split(':')
            row_1, col_1 = xl_cell_to_rowcol(cell_1)
            row_2, col_2 = xl_cell_to_rowcol(cell_2)
            new_args = [row_1, col_1, row_2, col_2]
            new_args.extend(args[1:])
            return method(self, *new_args)
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
def cell_wrapper(self, *args):

        try:
            # First arg is an int, default to row/col notation.
            int(args[0])
            return method(self, *args)
        except ValueError:
            # First arg isn't an int, convert to A1 notation.
            cell_1, cell_2 = args[0].split(':')
            row_1, col_1 = xl_cell_to_rowcol(cell_1)
            row_2, col_2 = xl_cell_to_rowcol(cell_2)
            new_args = [row_1, col_1, row_2, col_2]
            new_args.extend(args[1:])
            return method(self, *new_args)
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
cell_1, cell_2 = [col + '1' for col in args[0].split(':')]
            _, col_1 = xl_cell_to_rowcol(cell_1)
            _, col_2 = xl_cell_to_rowcol(cell_2)
            new_args = [col_1, col_2]
            new_args.extend(args[1:])
            return method(self, *new_args)

    return column_wrapper


###############################################################################
#
# Worksheet Class definition.
#
###############################################################################
class Worksheet(xmlwriter.XMLwriter):
    """
    A class for writing the Excel XLSX Worksheet file.

    """

    ###########################################################################
    #
    # Public API.
    #
    ###########################################################################

    def __init__(self):
        """
        Constructor.

        """
github jmcnamara / XlsxWriter / xlsxwriter / drawing.py View on Github external
if 'horizontal' in shape.align:
                align = shape.align['horizontal']
                if align == 'center':
                    attributes.append(('anchorCtr', '1'))
            else:
                attributes.append(('anchorCtr', '0'))

        self._xml_start_tag('xdr:txBody')
        self._xml_empty_tag('a:bodyPr', attributes)
        self._xml_empty_tag('a:lstStyle')

        lines = shape.text.split('\n')

        # Set the font attributes.
        font = shape.font
        style_attrs = Shape._get_font_style_attributes(font)
        latin_attrs = Shape._get_font_latin_attributes(font)
        style_attrs.insert(0, ('lang', font['lang']))

        if shape.textlink != '':
            attributes = [
                ('id', '{B8ADDEFE-BF52-4FD4-8C5D-6B85EF6FF707}'),
                ('type', 'TxLink')]

            self._xml_start_tag('a:p')
            self._xml_start_tag('a:fld', attributes)

            self._write_font_run(font, style_attrs, latin_attrs, 'a:rPr')

            self._xml_data_element('a:t', shape.text)
            self._xml_end_tag('a:fld')