How to Apply Border Style in Excel using Python. Openpyxl Tutorial #7

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everyone in this video we will learn how we can automate border styling in excel using open pi excel to begin with first we need to import open pi excel and create worksheet and workbook object let me do that real quick since we have to work with the borders we have to import additional package as well let's do that from open pi excel dot styles import border first we need to create an border object and then we can apply to particular cell or a column or a row as we have done for other properties in a previous video for font and pattern fill let's define a border here and see what argument it takes it takes multiple argument but most importance are these four so here we can define border of cell on foresight we can define a left side border right side border top border and bottom border and this takes side class as an input so we need to define the site class for each border side let's import sites as well we can import that directly here and call it site now let's first define site let's see what argument it takes so it takes side color and border style most of the time you only need to pass border style and color so border style has predefined value and you can only use those let me show those predefined value to you quickly you can only use this value in a border style so for our demo let's use dash and we can also add color this takes hex code so we need to go back to that website again and select a hex code for particular color let's uh go back all the way down and select reddish color and copy this hex code and we can directly pass that in our site argument we can use this particular side for any site we can use that as a left bottom top and right i will make this as a top side and i can directly pass that in my border argument let me comment this out here i can pass top equal to top and assign a variable to this border in whichever cell i apply this border it will give this style of dashed and this color let's go back to our excel sheet real quick let's target one of the cell so let's target this 516 and the location for the cell is b6 i can directly say w as b6 and to apply and border we need to use dot border property make it equal to the border we define i can add that here and since we are making a change in our excel sheet we have to send in save command let's run our python file python borders dot pi and we did not get any errors so let's go back to our excel sheet close this one open this excel sheet you can see here this 516 get upper border of rate it's really hard to see but let me deselect this cell you can see there is a dashed read border for this particular cell we can define multiple sites and assign those two different cells so for the same cell let's define bottom border as well let's make border style double and change the color so i will go to that website and pick any obvious color make it greenish copy the hex code add that in our python file here i can simply add bottom equal to bottom now my bottom side is defined and i can add that in my border if i rerun my python file before that let's close our excel sheet re-run my python file here we did not get any error so let's check if that patent doesn't apply and it didn't it you can see here for this particular cell b6 the top order is dashed in a raid and the bottom border is double and greenish color that's how you can apply border in python using open pi excel thank you for watching i will see you in the next video
Info
Channel: Python Bits
Views: 11,485
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 border style
Id: o0mS3IU4WfY
Channel Id: undefined
Length: 4min 36sec (276 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.