How to use the xlsxwriter.format.Format 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 jmcnamara / XlsxWriter / xlsxwriter / workbook.py View on Github external
properties: The format properties.

        Returns:
            Reference to a Format object.

        """
        format_properties = self.default_format_properties.copy()

        if self.excel2003_style:
            format_properties = {'font_name': 'Arial', 'font_size': 10,
                                 'theme': 1 * -1}

        if properties:
            format_properties.update(properties)

        xf_format = Format(format_properties,
                           self.xf_format_indices,
                           self.dxf_format_indices)

        # Store the format reference.
        self.formats.append(xf_format)

        return xf_format
github securestate / king-phisher / king_phisher / client / export.py View on Github external
"""
	Write the contents of a :py:class:`Gtk.ListStore` to an XLSX workseet.

	:param store: The store to export the information from.
	:type store: :py:class:`Gtk.ListStore`
	:param worksheet: The destination sheet for the store's data.
	:type worksheet: :py:class:`xlsxwriter.worksheet.Worksheet`
	:param dict columns: A dictionary mapping store column ids to the value names.
	:param xlsx_options: A collection of additional options for formatting the Excel Worksheet.
	:type xlsx_options: :py:class:`.XLSXWorksheetOptions`
	:return: The number of rows that were written.
	:rtype: int
	"""
	utilities.assert_arg_type(worksheet, xlsxwriter.worksheet.Worksheet, 2)
	utilities.assert_arg_type(columns, dict, 3)
	utilities.assert_arg_type(title_format, xlsxwriter.format.Format, 4)
	utilities.assert_arg_type(xlsx_options, (type(None), XLSXWorksheetOptions), 5)

	if xlsx_options is None:
		worksheet.set_column(0, len(columns), 30)
	else:
		for column, width in enumerate(xlsx_options.column_widths):
			worksheet.set_column(column, column, width)

	column_names, _ = _split_columns(columns)
	if xlsx_options is None:
		start_row = 0
	else:
		start_row = 2
		worksheet.merge_range(0, 0, 0, len(column_names) - 1, xlsx_options.title, title_format)
	row_count = liststore_export(store, columns, _xlsx_write, (worksheet,), row_offset=start_row, write_columns=False)
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
-1: Row or column is out of worksheet bounds.
            -2: String truncated to 32k characters.
            -3: 2 consecutive formats used.

        """
        tokens = list(args)
        cell_format = None
        str_length = 0
        string_index = 0

        # Check that row and col are valid and store max and min values
        if self._check_dimensions(row, col):
            return -1

        # If the last arg is a format we use it as the cell format.
        if isinstance(tokens[-1], Format):
            cell_format = tokens.pop()

        # Create a temp XMLWriter object and use it to write the rich string
        # XML to a string.
        fh = StringIO()
        self.rstring = XMLwriter()
        self.rstring._set_filehandle(fh)

        # Create a temp format with the default font for unformatted fragments.
        default = Format()

        # Convert list of format, string tokens to pairs of (format, string)
        # except for the first string fragment which doesn't require a default
        # formatting run. Use the default for strings without a leading format.
        fragments = []
        previous = 'format'
github jmcnamara / XlsxWriter / xlsxwriter / worksheet.py View on Github external
# Check that row and col are valid and store max and min values
        if self._check_dimensions(row, col):
            return -1

        # If the last arg is a format we use it as the cell format.
        if isinstance(tokens[-1], Format):
            cell_format = tokens.pop()

        # Create a temp XMLWriter object and use it to write the rich string
        # XML to a string.
        fh = StringIO()
        self.rstring = XMLwriter()
        self.rstring._set_filehandle(fh)

        # Create a temp format with the default font for unformatted fragments.
        default = Format()

        # Convert list of format, string tokens to pairs of (format, string)
        # except for the first string fragment which doesn't require a default
        # formatting run. Use the default for strings without a leading format.
        fragments = []
        previous = 'format'
        pos = 0

        for token in (tokens):
            if not isinstance(token, Format):
                # Token is a string.
                if previous != 'format':
                    # If previous token wasn't a format add one before string.
                    fragments.append(default)
                    fragments.append(token)
                else:
github jmcnamara / XlsxWriter / xlsxwriter / format.py View on Github external
def __init__(self, properties=None, xf_indices=None, dxf_indices=None):
        """
        Constructor.

        """
        if properties is None:
            properties = {}

        super(Format, self).__init__()

        self.xf_format_indices = xf_indices
        self.dxf_format_indices = dxf_indices
        self.xf_index = None
        self.dxf_index = None

        self.num_format = 'General'
        self.num_format_index = 0
        self.font_index = 0
        self.has_font = 0
        self.has_dxf_font = 0

        self.bold = 0
        self.underline = 0
        self.italic = 0
        self.font_name = 'Calibri'