Beispiel #1
0
    def apply_style_by_indexes(self, indexes_to_style, cols_to_style=None, styler_obj=None, bg_color=utils.colors.white,
                               bold=False, font='Arial', font_size=12, font_color=utils.colors.black, protection=False,
                               number_format=None, underline=None):
        """Applies a certain style to the provided indexes in the dataframe in the provided columns

        :param indexes_to_style: indexes to apply the style to
        :param cols_to_style: the columns to apply the style to, if not provided all the columns will be styled
        :param bg_color: the color to use.
        :param bold: bold or not
        :param font_size: the font size
        :param font_color: the font color
        :param protection: to protect the cell from changes or not
        :param number_format: modify the number format
        :param underline: the type of text underline
        :return: self
        :rtype: StyleFrame
        """

        if styler_obj:
            if not isinstance(styler_obj, Styler):
                raise TypeError(
                    'styler_obj must be {}, got {} instead.'.format(Styler.__name__, type(styler_obj).__name__))
            styler_obj = styler_obj.create_style()
        else:
            warnings.warn(DEPRECATION_MSG, DeprecationWarning)

        default_number_formats = {pd.tslib.Timestamp: 'DD/MM/YY HH:MM',
                                  dt.date: 'DD/MM/YY',
                                  dt.time: 'HH:MM'}

        indexes_number_format = number_format
        values_number_format = number_format

        if cols_to_style and not isinstance(cols_to_style, (list, tuple)):
            cols_to_style = [cols_to_style]
        elif not cols_to_style:
            cols_to_style = list(self.data_df.columns)
            for i in indexes_to_style:
                if not number_format:
                    indexes_number_format = default_number_formats.get(type(i.value), utils.number_formats.general)

                i.style = styler_obj or Styler(bg_color=bg_color, bold=bold, font=font, font_size=font_size,
                                               font_color=font_color, protection=protection,
                                               number_format=indexes_number_format, underline=underline).create_style()

        if not isinstance(indexes_to_style, (list, tuple, pd.Index)):
            indexes_to_style = [indexes_to_style]

        for index in indexes_to_style:
            for col in cols_to_style:
                if not number_format:
                    values_number_format = default_number_formats.get(type(self.ix[index.value, col].value), utils.number_formats.general)

                self.ix[index.value, col].style = styler_obj or Styler(bg_color=bg_color, bold=bold, font=font,
                                                                       font_size=font_size, font_color=font_color,
                                                                       protection=protection,
                                                                       number_format=values_number_format,
                                                                       underline=underline).create_style()
        return self
Beispiel #2
0
 def __init__(self, value, styler=None):
     self.value = value
     if styler is None:
         if isinstance(self.value, pd_timestamp):
             self.style = Styler(number_format=utils.number_formats.default_date_time_format)
         elif isinstance(self.value, dt.date):
             self.style = Styler(number_format=utils.number_formats.default_date_format)
         elif isinstance(self.value, dt.time):
             self.style = Styler(number_format=utils.number_formats.default_time_format)
         else:
             self.style = Styler()
     else:
         self.style = styler
Beispiel #3
0
 def __init__(self, value, styler=None):
     self.value = value
     if styler is None:
         if isinstance(self.value, pd.tslib.Timestamp):
             self.style = Styler(number_format='DD/MM/YY HH:MM').create_style()
         elif isinstance(self.value, dt.date):
             self.style = Styler(number_format='DD/MM/YY').create_style()
         elif isinstance(self.value, dt.time):
             self.style = Styler(number_format='HH:MM').create_style()
         else:
             self.style = Styler().create_style()
     else:
         self.style = styler
Beispiel #4
0
    def apply_column_style(self, cols_to_style, styler_obj=None, bg_color=utils.colors.white, font="Arial", bold=False, font_size=12, protection=False,
                           font_color=utils.colors.black, style_header=False, number_format=utils.number_formats.general,
                           underline=None):
        """apply style to a whole column

        :param cols_to_style: the columns to apply the style to
        :param bg_color:the color to use
        :param bold: bold or not
        :param font_size: the font size
        :param font_color: the font color
        :param style_header: style the header or not
        :param number_format: style the number format
        :param protection: to protect the column from changes or not
        :param underline: the type of text underline
        :return: self
        :rtype: StyleFrame
        """

        if styler_obj:
            if not isinstance(styler_obj, Styler):
                raise TypeError(
                    'styler_obj must be {}, got {} instead.'.format(Styler.__name__, type(styler_obj).__name__))
            styler_obj = styler_obj.create_style()
        else:
            warnings.warn(DEPRECATION_MSG, DeprecationWarning)

        if not isinstance(cols_to_style, (list, tuple)):
            cols_to_style = [cols_to_style]
        if not all(col in self.columns for col in cols_to_style):
            raise KeyError("one of the columns in {} wasn't found".format(cols_to_style))
        for col_name in cols_to_style:
            if style_header:
                self.columns[self.columns.get_loc(col_name)].style = styler_obj or Styler(bg_color=bg_color, bold=bold,
                                                                                          font=font, font_size=font_size,
                                                                                          font_color=font_color,
                                                                                          protection=protection,
                                                                                          number_format=number_format,
                                                                                          underline=underline).create_style()
                self._custom_headers_style = True
            for index in self.index:
                if isinstance(self.ix[index, col_name].value, pd.tslib.Timestamp):
                    number_format = utils.number_formats.date_time
                elif isinstance(self.ix[index, col_name].value, dt.date):
                    number_format = utils.number_formats.date
                elif isinstance(self.ix[index, col_name].value, dt.time):
                    number_format = utils.number_formats.time_24_hours
                self.ix[index, col_name].style = styler_obj or Styler(bg_color=bg_color, bold=bold, font=font,
                                                                      font_size=font_size, protection=protection,
                                                                      font_color=font_color, number_format=number_format,
                                                                      underline=underline).create_style()
        return self
Beispiel #5
0
    def apply_headers_style(self, styler_obj=None, bg_color=utils.colors.white, bold=True, font="Arial", font_size=12,
                            font_color=utils.colors.black, protection=False, number_format=utils.number_formats.general,
                            underline=None):
        """Apply style to the headers only

        :param bg_color:the color to use
        :param bold: bold or not
        :param font_size: the font size
        :param font_color: the font color
        :param number_format: openpy_style_obj the number format
        :param protection: to protect the column from changes or not
        :param underline: the type of text underline
        :return: self
        :rtype: StyleFrame
        """

        if styler_obj:
            if not isinstance(styler_obj, Styler):
                raise TypeError(
                    'styler_obj must be {}, got {} instead.'.format(Styler.__name__, type(styler_obj).__name__))

            styler_obj = styler_obj.create_style()
        else:
            warnings.warn(DEPRECATION_MSG, DeprecationWarning)

        for column in self.data_df.columns:
            column.style = styler_obj or Styler(bg_color=bg_color, bold=bold, font=font, font_size=font_size,
                                                font_color=font_color, protection=protection, number_format=number_format,
                                                underline=underline).create_style()
        self._custom_headers_style = True
        return self
from .message import Message
from styler import Styler

# In order to solve issue #2
s = Styler()


class LoadingSpinner(Message):
    """
    A loading spinner to add to message so that the user knows he has to wait.

    Parameters:
    -----------
    tag (tags): The tage of the message to use
    info (str): The info to print
    spinner (str): The type of spinner. Use one of ('bar', 'dot', 'equal')
    """
    def __init__(self, tag, info, spinner='bar'):
        self.text = info
        Message.__init__(self, tag, info, "\r")
        if spinner == 'bar':
            self.spinner = ['/', '-', '\\', '|']
        elif spinner == 'dot':
            self.spinner = ['   ', '.  ', '.. ', '...', ' ..', '  .']
        elif spinner == 'equal':
            self.spinner = [
                '[   ]', '[=  ]', '[== ]', '[===]', '[ ==]', '[  =]'
            ]
        else:
            raise ValueError("'spinner' can't be {}.".format(spinner))
        self.count = 0
Beispiel #7
0
    def __init__(self, obj, styler_obj=None):
        from_another_styleframe = False
        from_pandas_dataframe = False
        if styler_obj and not isinstance(styler_obj, Styler):
            raise TypeError('styler_obj must be {}, got {} instead.'.format(
                Styler.__name__,
                type(styler_obj).__name__))
        if isinstance(obj, pd.DataFrame):
            from_pandas_dataframe = True
            if obj.empty:
                self.data_df = deepcopy(obj)
            else:
                self.data_df = obj.applymap(
                    lambda x: Container(x, deepcopy(styler_obj))
                    if not isinstance(x, Container) else x)
        elif isinstance(obj, pd.Series):
            self.data_df = obj.apply(
                lambda x: Container(x, deepcopy(styler_obj))
                if not isinstance(x, Container) else x)
        elif isinstance(obj, (dict, list)):
            self.data_df = pd.DataFrame(obj).applymap(
                lambda x: Container(x, deepcopy(styler_obj))
                if not isinstance(x, Container) else x)
        elif isinstance(obj, StyleFrame):
            self.data_df = deepcopy(obj.data_df)
            from_another_styleframe = True
        else:
            raise TypeError("{} __init__ doesn't support {}".format(
                type(self).__name__,
                type(obj).__name__))
        self.data_df.columns = [
            Container(col, deepcopy(styler_obj))
            if not isinstance(col, Container) else deepcopy(col)
            for col in self.data_df.columns
        ]
        self.data_df.index = [
            Container(index, deepcopy(styler_obj))
            if not isinstance(index, Container) else deepcopy(index)
            for index in self.data_df.index
        ]

        if from_pandas_dataframe:
            self.data_df.index.name = obj.index.name

        self._columns_width = obj._columns_width if from_another_styleframe else {}
        self._rows_height = obj._rows_height if from_another_styleframe else {}
        self._has_custom_headers_style = obj._has_custom_headers_style if from_another_styleframe else False
        self._cond_formatting = []
        self._default_style = styler_obj or Styler()
        self._index_header_style = obj._index_header_style if from_another_styleframe else self._default_style

        self._known_attrs = {
            'at': self.data_df.at,
            'loc': self.data_df.loc,
            'iloc': self.data_df.iloc,
            'applymap': self.data_df.applymap,
            'groupby': self.data_df.groupby,
            'index': self.data_df.index,
            'columns': self.data_df.columns,
            'fillna': self.data_df.fillna
        }
Beispiel #8
0
    def to_excel(self,
                 excel_writer='output.xlsx',
                 sheet_name='Sheet1',
                 allow_protection=False,
                 right_to_left=False,
                 columns_to_hide=None,
                 row_to_add_filters=None,
                 columns_and_rows_to_freeze=None,
                 best_fit=None,
                 **kwargs):
        """Saves the dataframe to excel and applies the styles.

        :param str|pandas.ExcelWriter excel_writer: File path or existing ExcelWriter
        :param str sheet_name: Name of sheet the StyleFrame will be exported to
        :param bool right_to_left: sets the sheet to be right to left.
        :param None|str|list|tuple|set columns_to_hide: single column, list, set or tuple of columns to hide, may be column index (starts from 1)
                                column name or column letter.
        :param bool allow_protection: allow to protect the sheet and the cells that specified as protected.
        :param None|int row_to_add_filters: add filters to the given row, starts from zero (zero is to add filters to columns).
        :param None|str columns_and_rows_to_freeze: column and row string to freeze for example: C3 will freeze columns: A,B and rows: 1,2.
        :param None|str|list|tuple|set best_fit: single column, list, set or tuple of columns names to attempt to best fit the width
                                for.

        See Pandas.DataFrame.to_excel documentation about other arguments
        """

        # dealing with needed pandas.to_excel defaults
        header = kwargs.pop('header', True)
        index = kwargs.pop('index', False)
        startcol = kwargs.pop('startcol', 0)
        startrow = kwargs.pop('startrow', 0)
        na_rep = kwargs.pop('na_rep', '')

        def get_values(x):
            if isinstance(x, Container):
                return x.value
            else:
                try:
                    if np.isnan(x):
                        return na_rep
                    else:
                        return x
                except TypeError:
                    return x

        def within_sheet_boundaries(row=1, column='A'):
            return (1 <= int(row) <= sheet.max_row and 1 <=
                    cell.column_index_from_string(column) <= sheet.max_column)

        def get_range_of_cells(row_index=None, columns=None):
            if columns is None:
                start_letter = self._get_column_as_letter(
                    sheet, self.data_df.columns[0], startcol)
                end_letter = self._get_column_as_letter(
                    sheet, self.data_df.columns[-1], startcol)
            else:
                start_letter = self._get_column_as_letter(
                    sheet, columns[0], startcol)
                end_letter = self._get_column_as_letter(
                    sheet, columns[-1], startcol)
            if row_index is None:  # returns cells range for the entire dataframe
                start_index = startrow + 1
                end_index = start_index + len(self)
            else:
                start_index = startrow + row_index + 1
                end_index = start_index
            return '{start_letter}{start_index}:{end_letter}{end_index}'.format(
                start_letter=start_letter,
                start_index=start_index,
                end_letter=end_letter,
                end_index=end_index)

        if len(self.data_df) > 0:
            export_df = self.data_df.applymap(get_values)

        else:
            export_df = deepcopy(self.data_df)

        export_df.columns = [col.value for col in export_df.columns]
        # noinspection PyTypeChecker
        export_df.index = [row_index.value for row_index in export_df.index]
        export_df.index.name = self.data_df.index.name

        if isinstance(excel_writer, (str_type, unicode_type)):
            excel_writer = self.ExcelWriter(excel_writer)

        export_df.to_excel(excel_writer,
                           sheet_name=sheet_name,
                           engine='openpyxl',
                           header=header,
                           index=index,
                           startcol=startcol,
                           startrow=startrow,
                           na_rep=na_rep,
                           **kwargs)

        sheet = excel_writer.sheets[sheet_name]

        sheet.sheet_view.rightToLeft = right_to_left

        self.data_df.fillna(Container('NaN'), inplace=True)

        if index:
            if self.data_df.index.name:
                index_name_cell = sheet.cell(row=startrow + 1,
                                             column=startcol + 1)
                index_name_cell.style = self._index_header_style.to_openpyxl_style(
                )
            for row_index, index in enumerate(self.data_df.index):
                try:
                    style_to_apply = index.style.to_openpyxl_style()
                except AttributeError:
                    style_to_apply = index.style
                current_cell = sheet.cell(row=startrow + row_index + 2,
                                          column=startcol + 1)
                current_cell.style = style_to_apply
                if isinstance(index.style, Styler):
                    current_cell.comment = index.style.generate_comment()
                else:
                    if hasattr(index.style, 'comment'):
                        index.style.comment.parent = None
                        current_cell.comment = index.style.comment

            startcol += 1

        if header and not self._has_custom_headers_style:
            self.apply_headers_style(Styler.default_header_style())

        # Iterating over the dataframe's elements and applying their styles
        # openpyxl's rows and cols start from 1,1 while the dataframe is 0,0
        for col_index, column in enumerate(self.data_df.columns):
            try:
                style_to_apply = column.style.to_openpyxl_style()
            except AttributeError:
                style_to_apply = column.style
            column_header_cell = sheet.cell(row=startrow + 1,
                                            column=col_index + startcol + 1)
            column_header_cell.style = style_to_apply
            if isinstance(column.style, Styler):
                column_header_cell.comment = column.style.generate_comment()
            else:
                if hasattr(column.style, 'comment'):
                    column.style.comment.parent = None
                    column_header_cell.comment = column.style.comment
            for row_index, index in enumerate(self.data_df.index):
                current_cell = sheet.cell(row=row_index + startrow + 2,
                                          column=col_index + startcol + 1)
                data_df_style = self.data_df.at[index, column].style
                try:
                    if '=HYPERLINK' in unicode_type(current_cell.value):
                        data_df_style.font_color = utils.colors.blue
                        data_df_style.underline = utils.underline.single
                    else:
                        if best_fit and column.value in best_fit:
                            data_df_style.wrap_text = False
                            data_df_style.shrink_to_fit = False
                    try:
                        style_to_apply = data_df_style.to_openpyxl_style()
                    except AttributeError:
                        style_to_apply = data_df_style
                    current_cell.style = style_to_apply
                    if isinstance(data_df_style, Styler):
                        current_cell.comment = data_df_style.generate_comment()
                    else:
                        if hasattr(data_df_style, 'comment'):
                            data_df_style.comment.parent = None
                            current_cell.comment = data_df_style.comment
                except AttributeError:  # if the element in the dataframe is not Container creating a default style
                    current_cell.style = Styler().to_openpyxl_style()

        if best_fit:
            if not isinstance(best_fit, (list, set, tuple)):
                best_fit = [best_fit]
            self.set_column_width_dict({
                column: (max(self.data_df[column].astype(str).str.len()) +
                         self.A_FACTOR) * self.P_FACTOR
                for column in best_fit
            })

        for column in self._columns_width:
            column_letter = self._get_column_as_letter(sheet, column, startcol)
            sheet.column_dimensions[column_letter].width = self._columns_width[
                column]

        for row in self._rows_height:
            if within_sheet_boundaries(row=(row + startrow)):
                sheet.row_dimensions[startrow +
                                     row].height = self._rows_height[row]
            else:
                raise IndexError('row: {} is out of range'.format(row))

        if row_to_add_filters is not None:
            try:
                row_to_add_filters = int(row_to_add_filters)
                if not within_sheet_boundaries(row=(row_to_add_filters +
                                                    startrow + 1)):
                    raise IndexError('row: {} is out of rows range'.format(
                        row_to_add_filters))
                sheet.auto_filter.ref = get_range_of_cells(
                    row_index=row_to_add_filters)
            except (TypeError, ValueError):
                raise TypeError("row must be an index and not {}".format(
                    type(row_to_add_filters)))

        if columns_and_rows_to_freeze is not None:
            if not isinstance(columns_and_rows_to_freeze,
                              (str_type, unicode_type
                               )) or len(columns_and_rows_to_freeze) < 2:
                raise TypeError(
                    "columns_and_rows_to_freeze must be a str for example: 'C3'"
                )
            if not within_sheet_boundaries(
                    column=columns_and_rows_to_freeze[0]):
                raise IndexError("column: %s is out of columns range." %
                                 columns_and_rows_to_freeze[0])
            if not within_sheet_boundaries(row=columns_and_rows_to_freeze[1]):
                raise IndexError("row: %s is out of rows range." %
                                 columns_and_rows_to_freeze[1])
            sheet.freeze_panes = sheet[columns_and_rows_to_freeze]

        if allow_protection:
            sheet.protection.autoFilter = False
            sheet.protection.enable()

        # Iterating over the columns_to_hide and check if the format is columns name, column index as number or letter
        if columns_to_hide:
            if not isinstance(columns_to_hide, (list, set, tuple)):
                columns_to_hide = [columns_to_hide]

            for column in columns_to_hide:
                column_letter = self._get_column_as_letter(
                    sheet, column, startcol)
                sheet.column_dimensions[column_letter].hidden = True

        for cond_formatting in self._cond_formatting:
            sheet.conditional_formatting.add(
                get_range_of_cells(columns=cond_formatting.columns),
                cond_formatting.rule)

        return excel_writer
Beispiel #9
0
CONTENT_IMG_NAME = "lion.jpg"
STYLE_IMG_NAME = "starry-night.jpg"
OUTPUT_NAME = "test"
NUM_FRAMES = 24 * 12

custom_params = dict(
    max_dimsize=512,
    num_iters=100,
    content_weight=0.0,
    init_img_type='custom',
)

default_config = StyleConfig()
default_config.update(**custom_params)
styler = Styler(default_config, device)


def zoom(image, zoom_pixels):
    # PIL image -> remove borders -> resize -> PIL Image
    width, height = image.size
    left, right = zoom_pixels, width - zoom_pixels
    top, bottom = zoom_pixels, height - zoom_pixels
    return image.crop((left, top, right, bottom)).resize((width, height))


content_image = Image.open(util.content_img_path(CONTENT_IMG_NAME))
style_image = Image.open(util.style_img_path(STYLE_IMG_NAME))

last_frame_result = content_image
for frame in range(NUM_FRAMES):
Beispiel #10
0
    def to_excel(self,
                 excel_writer='output.xlsx',
                 sheet_name='Sheet1',
                 na_rep='',
                 float_format=None,
                 columns=None,
                 header=True,
                 index=False,
                 index_label=None,
                 startrow=0,
                 startcol=0,
                 merge_cells=True,
                 encoding=None,
                 inf_rep='inf',
                 allow_protection=False,
                 right_to_left=False,
                 columns_to_hide=None,
                 row_to_add_filters=None,
                 columns_and_rows_to_freeze=None):
        """Saves the dataframe to excel and applies the styles.

        :param right_to_left: sets the sheet to be right to left.
        :param columns_to_hide: single column, list or tuple of columns to hide, may be column index (starts from 1)
                                column name or column letter.
        :param allow_protection: allow to protect the sheet and the cells that specified as protected.
        :param row_to_add_filters: add filters to the given row, starts from zero (zero is to add filters to columns).
        :param columns_and_rows_to_freeze: column and row string to freeze for example: C3 will freeze columns: A,B and rows: 1,2.

        See Pandas' to_excel documentation about the other parameters
        """
        def get_values(x):
            if isinstance(x, Container):
                return x.value
            else:
                try:
                    if np.isnan(x):
                        return na_rep
                    else:
                        return x
                except TypeError:
                    return x

        def get_column_as_letter(column_to_convert):
            if not isinstance(column_to_convert,
                              (int, basestring if PY2 else str, Container)):
                raise TypeError(
                    "column must be an index, column letter or column name")
            column_as_letter = None
            if column_to_convert in self.data_df.columns:  # column name
                column_index = self.data_df.columns.get_loc(
                    column_to_convert
                ) + startcol + 1  # worksheet columns index start from 1
                column_as_letter = cell.get_column_letter(column_index)

            elif isinstance(column_to_convert,
                            int) and column_to_convert >= 1:  # column index
                column_as_letter = cell.get_column_letter(startcol +
                                                          column_to_convert)
            elif column_to_convert in sheet.column_dimensions:  # column letter
                column_as_letter = column_to_convert

            if column_as_letter is None or column_as_letter not in sheet.column_dimensions:
                raise IndexError("column: %s is out of columns range." %
                                 column_to_convert)

            return column_as_letter

        def get_range_of_cells_for_specific_row(row_index):
            start_letter = get_column_as_letter(
                column_to_convert=self.data_df.columns[0])
            end_letter = get_column_as_letter(
                column_to_convert=self.data_df.columns[-1])
            return '{start_letter}{start_index}:{end_letter}{end_index}'.format(
                start_letter=start_letter,
                start_index=startrow + row_index + 1,
                end_letter=end_letter,
                end_index=startrow + row_index + 1)

        if len(self.data_df) > 0:
            export_df = self.data_df.applymap(get_values)

        else:
            export_df = deepcopy(self.data_df)

        export_df.columns = [col.value for col in export_df.columns]
        # noinspection PyTypeChecker
        export_df.index = [row_index.value for row_index in export_df.index]

        if isinstance(excel_writer, basestring if PY2 else str):
            excel_writer = self.ExcelWriter(excel_writer)

        export_df.to_excel(excel_writer,
                           sheet_name=sheet_name,
                           na_rep=na_rep,
                           float_format=float_format,
                           index=index,
                           columns=columns,
                           header=header,
                           index_label=index_label,
                           startrow=startrow,
                           startcol=startcol,
                           engine='openpyxl',
                           merge_cells=merge_cells,
                           encoding=encoding,
                           inf_rep=inf_rep)

        sheet = excel_writer.book.get_sheet_by_name(sheet_name)

        sheet.sheet_view.rightToLeft = right_to_left

        self.data_df.fillna(Container('NaN'), inplace=True)

        if index:
            for row_index, index in enumerate(self.data_df.index):
                sheet.cell(row=startrow + row_index + 2,
                           column=startcol + 1).style = index.style
            startcol += 1

        if header and not self._custom_headers_style:
            self.apply_headers_style(Styler.default_header_style())

        # Iterating over the dataframe's elements and applying their styles
        # openpyxl's rows and cols start from 1,1 while the dataframe is 0,0
        for col_index, column in enumerate(self.data_df.columns):
            sheet.cell(row=startrow + 1,
                       column=col_index + startcol + 1).style = column.style

            for row_index, index in enumerate(self.data_df.index):
                current_cell = sheet.cell(row=row_index + startrow + 2,
                                          column=col_index + startcol + 1)
                try:
                    if PY2:
                        if '=HYPERLINK' in unicode(current_cell.value):
                            current_bg_color = current_cell.style.fill.fgColor.rgb
                            current_font_size = current_cell.style.font.size
                            current_cell.style = Styler(
                                bg_color=current_bg_color,
                                font_color=utils.colors.blue,
                                font_size=current_font_size,
                                number_format=utils.number_formats.general,
                                underline=utils.underline.single).create_style(
                                )
                        else:
                            current_cell.style = self.data_df.loc[index,
                                                                  column].style

                    else:
                        if '=HYPERLINK' in str(current_cell.value):
                            current_bg_color = current_cell.style.fill.fgColor.rgb
                            current_font_size = current_cell.style.font.size
                            current_cell.style = Styler(
                                bg_color=current_bg_color,
                                font_color=utils.colors.blue,
                                font_size=current_font_size,
                                number_format=utils.number_formats.general,
                                underline='single').create_style()
                        else:
                            current_cell.style = self.data_df.loc[index,
                                                                  column].style

                except AttributeError:  # if the element in the dataframe is not Container creating a default style
                    current_cell.style = Styler().create_style()

        for column in self._columns_width:
            column_letter = get_column_as_letter(column_to_convert=column)
            sheet.column_dimensions[column_letter].width = self._columns_width[
                column]

        for row in self._rows_height:
            if row + startrow in sheet.row_dimensions:
                sheet.row_dimensions[startrow +
                                     row].height = self._rows_height[row]
            else:
                raise IndexError('row: {} is out of range'.format(row))

        if row_to_add_filters is not None:
            try:
                row_to_add_filters = int(row_to_add_filters)
                if (row_to_add_filters + startrow +
                        1) not in sheet.row_dimensions:
                    raise IndexError('row: {} is out of rows range'.format(
                        row_to_add_filters))
                sheet.auto_filter.ref = get_range_of_cells_for_specific_row(
                    row_index=row_to_add_filters)
            except (TypeError, ValueError):
                raise TypeError("row must be an index and not {}".format(
                    type(row_to_add_filters)))

        if columns_and_rows_to_freeze is not None:
            if not isinstance(columns_and_rows_to_freeze, basestring if PY2
                              else str) or len(columns_and_rows_to_freeze) < 2:
                raise TypeError(
                    "columns_and_rows_to_freeze must be a str for example: 'C3'"
                )
            if columns_and_rows_to_freeze[0] not in sheet.column_dimensions:
                raise IndexError("column: %s is out of columns range." %
                                 columns_and_rows_to_freeze[0])
            if int(columns_and_rows_to_freeze[1]) not in sheet.row_dimensions:
                raise IndexError("row: %s is out of rows range." %
                                 columns_and_rows_to_freeze[1])
            sheet.freeze_panes = sheet[columns_and_rows_to_freeze]

        if allow_protection:
            sheet.protection.autoFilter = False
            sheet.protection.enable()

        # Iterating over the columns_to_hide and check if the format is columns name, column index as number or letter
        if columns_to_hide:
            if not isinstance(columns_to_hide, (list, tuple)):
                columns_to_hide = [columns_to_hide]

            for column in columns_to_hide:
                column_letter = get_column_as_letter(column_to_convert=column)
                sheet.column_dimensions[column_letter].hidden = True

        return excel_writer