Package: openpyxl-style-writer
openpyxl_style_writerThis is a wrapper base onopenpyxlpackage. The original feature to create resuable style (NameStyled) is not avaliable forwrite only mode. Thus this package aimed to provide a easy way for user to create resuable styles and use it onwrite only modeeasilyInstallation$ pip install openpyxl_style_writerUsageExamplefromopenpyxl_style_writerimportCustomStyle,DefaultStyle,RowWriterif__name__=='__main__':workbook=RowWriter()# enable protection by protection=Trueworkbook.create_sheet('ExampleSheet',protection=True)title='This is an example'row_title_1=['fruits','fruits','animals','animals']row_title_2=['apple','banana','cat','dog']percent_data=[0.1,0.6,0.225,0.4755,0.9,1]data=[10,20,30,40]# append single cell with Default Styleworkbook.row_append(title)workbook.set_cell_width(1,30)workbook.create_row()foriteminrow_title_1:workbook.row_append(item)workbook.create_row()# set custom Default Style and append list in a rowblue_font_style={'color':'0000ff','bold':True,'size':8}DefaultStyle.set_default(font_params=blue_font_style)workbook.row_append_list(row_title_2)workbook.create_row()# create new Custom Style and give row_append_list a stylepink_fill_style={'patternType':'solid','fgColor':'d25096'}# add protect to pink_stylepink_style=CustomStyle(fill_params=pink_fill_style,protect=True)workbook.row_append_list(data,pink_style)workbook.create_row()# create number_format stylepercent_style=CustomStyle(font_size=8,number_format='0.0%')workbook.row_append_list(percent_data,percent_style)workbook.create_row()workbook.save('example.xlsx')CustomStyle & DefaultStyleYou can either set theCustomStyleandDefaultStyleby the key words from openpyxl or from this package. Here is an example to create aCustomStyleby the openpyxl key words.fromopenpyxl_style_writerimportCustomStyle# Create the style by the original key words from openpyxlblue_title_font={'color':'0000ff','bold':True,'size':15,}cyan_title_pattern={'patternType':'solid','fgColor':'00ffff	'}# Use font_params and fill_params to create a reusable style with the blue font and cyan fill.# The style you do not set will use the style of DefaultStyle.custom_title_style=CustomStyle(font_params=blue_title_font,fill_params=cyan_titl_patter,)You could also set yourDefaultStylefirst, and the rest of theCustomStylewill follow the settings ofDefaultStyleif the style do not set inCustomStyle.fromopenpyxl_style_writerimportCustomStyle,DefaultStylecyan_title_pattern={'patternType':'solid','fgColor':'00ffff	'}blue_title_font={'color':'0000ff','bold':True,'size':15,}# set default style with cyan fillDefaultStyle.set_default(fill_params=cyan_title_pattern)# This custom style will show blue font and cyan fill, although it only set the font_paramscustom_title_style=CustomStyle(font_params=blue_title_font,)If you want to do it in simple way, openpyxl_style_writer offer a map for somecommon key words. You can use the key words of openpyxl_style_writer.fromopenpyxl_style_writerimportCustomStylecustom_title_style=CustomStyle(font_size=15,font_name='Calibri',)Or you can use both methodsfromopenpyxl_style_writerimportCustomStyleblue_title_font={'color':'0000ff','bold':True,'size':15,}custom_title_style=CustomStyle(font_size=15,font_name='Calibri',fill_params=cyan_title_pattern)Advanced UsageIn scenarios where you want to establish a collection of reusable styles for your Excel documents or if you have a variety of different Excel outputs, you can define a base class containing multiple custom styles and then inherit from this base class in your Excel class.The following example demonstrates how to achieve this using the openpyxl_style_writer library:fromopenpyxl_style_writerimportCustomStyle,RowWriterclassBaseExcelWriter(RowWriter):blue_font={'color':'0000ff','bold':True,'size':15,}cyan_title_pattern={'patternType':'solid','fgColor':'00ffff	'}blue_font_style=CustomStyle(font_params=blue_font)cyan_fill_style=CustomStyle(fill_params=cyan_title_pattern)classExampleExcel(BaseExcelWriter):first_row=['Apple','Banana','Cat']defcreate(self,file_name='output.xlsx'):self.create_sheet('ExampleSheet',protection=True)self.row_append_list(self.first_row,style=self.cyan_fill_style)self.create_row()foridx,_inenumerate(self.first_row):self.row_append(idx,style=self.blue_font_style)self.create_row()self.save(file_name)classExampleExcel2(BaseExcelWriter):defcreate(self,file_name='output.xlsx'):# create a content of excel2...if__name__=='__main__':example=ExampleExcel()example.create('example.xlsx')List of Key words in openpyxl_style_writerThis is a list of the key words in openpyxl_style_writer and how it map to the attributes of openpyxlclassKeydatatypemap tofontfont_sizeintopenpyxl.styles.Font.sizefont_namestropenpyxl.styles.Font.namefont_boldboolopenpyxl.styles.Font.boldfont_italicboolopenpyxl.styles.Font.italicfont_underlinestropenpyxl.styles.Font.underlinefont_strikeboolopenpyxl.styles.Font.strikefont_vertAlignstropenpyxl.styles.Font.vertAlignfont_colorstropenpyxl.styles.Font.colorfillfill_colorstropenpyxl.styles.PatternFill.coloralignmentali_horizontalstropenpyxl.styles.Alignment.colorali_verticalstropenpyxl.styles.Alignment.colorali_wrap_textstropenpyxl.styles.Alignment.colorborderborder_style_topstropenpyxl.styles.Border.top with openpyxl.styles.Side.border_styleborder_style_rightstropenpyxl.styles.Border.right with openpyxl.styles.Side.border_styleborder_style_leftstropenpyxl.styles.Border.left with openpyxl.styles.Side.border_styleborder_style_bottomstropenpyxl.styles.Border.bottom with openpyxl.styles.Side.border_styleborder_color_topstropenpyxl.styles.Border.top with openpyxl.styles.Side.colorborder_color_rightstropenpyxl.styles.Border.right with openpyxl.styles.Side.colorborder_color_leftstropenpyxl.styles.Border.left with openpyxl.styles.Side.colorborder_color_bottomstropenpyxl.styles.Border.bottom with openpyxl.styles.Side.color