How to Apply Pattern Fill/Background Color in Excel using Python. Openpyxl Tutorial #6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video we will learn about patent filling in excel using open pi excel first we will need to import open pi excel then we need to create workbook object and i have already created a workbook so i will use that also we need to create a worksheet object we can create that and i have one defined in my worksheet if you want to learn about workbook and worksheet object mode please watch the first video of this series now let me first show you what is pattern filling it's basically a background color of a cell here if i select b5 i can give it a background color we can automate using open pi excel using the pattern filling let me select no fill here and let's go back to our python sheet and see how we can automate that to do that first we need to import pattern filling we can say from open pi excel dot styles import pattern fill now we have to define a pattern fill to do that we can say pattern fill and it takes many argument but most of the time we only need to pass two one we need to pass a pattern type and pattern type is basically type of pattern that we want to highlight in there there are a predefined value and we can only use those let me show that to you real quick we can only specify these values in pattern fill and i will post these values in description so you can use that as a reference for this one let's use a solid so i'll add solid in here second argument we need to define is f g color now this fc color needs to be a hex code let me comment this out we can go to a website that we used in a previous video here we can select a color and get the hex code let's select this color and copy this hex code go back to our python sheet and paste it here now let's assign a variable to this pattern fill so we can use that letter i'll call it fill pattern since it's going out of view i'll break that down into two lines we can target a particular cell let's go back to our excel series and see where we want to target let's target this 1500 and apply that fill pattern so 1500 is in cell b4 i can call it using indexing and say wsb4 i can assign this to a variable and then assign fill pattern or i can directly say dot fill equal to fill pattern and since we are making the change in excel sheet we always have to send w dot save command if i run my python file pattern field dot y and we get an error so let's see what it says w dot save balance worksheet object has no attribute so you oh get it actually we can only save the workbook not the worksheet so let me change that real quick and say wb dot save and let's rerun our python file we did not get any error i will close this actual file and reopen it and you can see that pattern fill is applied to that particular cell b4 so that's how you can do pattern fill in excel using open pi excel thank you for watching i will see you in the next video
Info
Channel: Python Bits
Views: 17,252
Rating: undefined out of 5
Keywords: python tutorial, python programming, learn python, python for beginners, read excel in python, write excel in python, write excel in python openpyxl, excel read and write in python, openpyxl tutorials, read excel files in python, python how to read microsoft excel files, openpyxl, microsoft excel python, excel python, python xlsx, python openpyxl, openpyxl tutorial, python openpyxl background fill
Id: osFd-8B146w
Channel Id: undefined
Length: 3min 56sec (236 seconds)
Published: Mon Jan 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.