Read And Write Excel Files In Python Using Openpyxl In PyCharm- Excel Styling and formatting Python

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • In this video, we will discuss different ways to read excel in python and we will also discuss how to perform write operations as well.
    We have many libraries which allow us to read excel but I personally prefer openpyxl. You can also go ahead with panda library.
    Python Excel Lib
    www.python-exc...
    Python Series
    • Python Tutorials For B...
    Blog
    learn-automatio...
    All Playlist
    / mukeshotwani
    Connect with us:
    Linkedin- / mukesh-otwani-93631b99
    Instagram- / mukeshotwani
    Facebook Group- / 256655817858291
    Facebook Page- / seleniumwebdrivermukesh
    Twitter- / mukeshotwani
    Blog- learn-automatio...

Комментарии • 295

  • @Frostbyte-Game-Studio
    @Frostbyte-Game-Studio 3 года назад +61

    how many times have i been saved by indians

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +2

      Thanks Arvin 🙏🙏

    • @mohanapriya4372
      @mohanapriya4372 3 года назад +3

      it doesn't matter where we come from.. its all about the effort we put so far.. don't make any controversial thoughts brother..

  • @ibatuhanozdemirr
    @ibatuhanozdemirr 3 года назад +7

    For some reason your video appears as 4th video when i search openpyxl. But this is miles better than the first 3. Great job.

  • @vaibhavparsadi5986
    @vaibhavparsadi5986 3 года назад +10

    This is the best lesson I have come across in RUclips!

  • @mohammedaskar4268
    @mohammedaskar4268 Месяц назад +1

    Thanks!

  • @KC-pi6po
    @KC-pi6po 3 года назад +3

    Perfect explanation for something i should have remembered from my courses a few years ago. I hope many more people find this video, because changing excel-files this way is very useful to me. Please accept my humble upvote and support

  • @samsahoo2006
    @samsahoo2006 3 года назад +1

    Very Nice and detailed. All other videos doesn't tell about the basic. Need to refer to their all other videos to understand what they are doing. I love this tutorial. Solves my specific need.

  • @anirudhramaswamy786
    @anirudhramaswamy786 3 года назад +2

    you make stuffs easy to learn
    !! thanks a lot !

  • @johncheung4905
    @johncheung4905 3 года назад +1

    The best tutorial on automating Excel with python. Thank you !!!!!

  • @SurenderKumar-ov7pd
    @SurenderKumar-ov7pd 2 года назад +1

    Thank you very much. Because of your video I could solve the problem persisting for 2-3 days. Thanks again

  • @sandeepnallala48
    @sandeepnallala48 3 года назад +1

    I came across this channel for 1st time and its really cool to learn these things from such a teacher, thank you sir : )
    it helped me. thanks sir : )

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Thank you so much Sandeep for such a beautiful comment.

  • @brijrajkacha9839
    @brijrajkacha9839 3 года назад +2

    Thank you sir, i attended full session and make a notes of it.
    Sir, please make a vedio on readig and writing txt file using python.

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Briraj, here is the video ruclips.net/video/Pj2YDQw10k8/видео.html

  • @budisudra
    @budisudra 2 года назад +1

    very clear step by step exlpanation. Good Job

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      Glad it was helpful! Thanks Budi

  • @prashanthsriramsetty8998
    @prashanthsriramsetty8998 2 года назад

    explained very well in detail. I highly recommend this video who are trying to learn from scratch.

  • @blameItleaveit
    @blameItleaveit 3 года назад +2

    Clean and concise 👌

  • @bangtap2613
    @bangtap2613 2 года назад

    Mukesh, you have been a huge help, Many thanks, mate. I look forward to viewing your other videos. Thanks !!

  • @harpritsinhyadav7271
    @harpritsinhyadav7271 3 года назад +2

    Clearly explained.Thank you for this great tutorial.

  • @Imran20091990
    @Imran20091990 2 года назад

    Excellent..very useful 👏👏👏

  • @nikitakeche3905
    @nikitakeche3905 2 года назад

    Thanks for the video.. it cleared my concept

  • @samratkamble5820
    @samratkamble5820 3 года назад +1

    Detailed explanation.. helped me to go from scratch.. thank you..

  • @alaingoulet4468
    @alaingoulet4468 3 года назад +2

    Great presentation. I really like how you make sure we understand what is happening on more difficult coding.

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Thanks Alain, this means a lot to me.

  • @SkyHighWithMe
    @SkyHighWithMe 2 года назад +1

    I laughed so hard when you were waiting for the excel sheet and didn't show up because of error 'solid'. XD. Great content. This video helped me in my project. Thank you

  • @ganeshdevarshetty4405
    @ganeshdevarshetty4405 2 года назад +1

    Bhai Maja aa gaya...

  • @pradeepraghavan6407
    @pradeepraghavan6407 2 года назад +1

    great tutorial very helpful thanks you very much.

  • @sapankushwaha4069
    @sapankushwaha4069 2 года назад +1

    simple and shandarr!!!!

  • @jiten4486
    @jiten4486 3 года назад +1

    Great video! Best I’ve come across after multiple searches. Thank you for this

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      You're very welcome! Jitendra and I am really glad you like this videos.

  • @senthilmanickam1671
    @senthilmanickam1671 3 года назад +1

    Good lesson I have come across in RUclips! very Nice

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Awesome, thank you so much Senthil.

  • @pavansrinivasvedantham9006
    @pavansrinivasvedantham9006 2 года назад

    Very nice explanation... thank you

  • @graceangeline9990
    @graceangeline9990 2 года назад

    your are really saved me.... thnx bro

  • @AllOut842
    @AllOut842 2 года назад +1

    Great video…. Like you presentation a lot

  • @josemariavicentetascon8428
    @josemariavicentetascon8428 3 года назад +1

    Good Lesson and thank you very much for sharing your knowledge

  • @vikassinghal2103
    @vikassinghal2103 3 года назад +3

    Hi Mukesh, I was watching your openpyxl video which is really good. Do you have any video on using openpyxl on POM pattern with Pytest framework. I mean reading and writing data from/into excel using POM and pytest. Could you please share that ?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Complete framework series coming soon Vikas.

  • @mvvishy
    @mvvishy 3 года назад +1

    Very nice tutorial Sir. Thank you.

  • @Chuquemeka
    @Chuquemeka 3 года назад +1

    Wow! A very big thank you for this.

  • @asit05
    @asit05 2 года назад

    Great explation...

  • @niruandhp8772
    @niruandhp8772 3 года назад +1

    Awsome Class

  • @suryakantthakur1879
    @suryakantthakur1879 3 года назад +1

    The best one....Thank you very much.

  • @khalidjj2073
    @khalidjj2073 3 года назад +2

    Very nice video!
    Questions
    I have a folder with a hundreds of csv files. 1. How can I print out the same row and column and save it to a new file
    2. How can I write or update the same row/column with new value
    Thanks
    Please more videos...

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Khalid, what is the doubt here?

    • @khalidjj2073
      @khalidjj2073 3 года назад

      No doubt. Just need help with my questions
      I have a folder with hundreds of csv files
      ***Looking for puthoncode exampme to achieve
      Wanted to ask one other question
      How to move files with a keyword file names to a specific folder. Move similar keyword files from a folder into its own unique folder
      Thank you Mukesh!

  • @mustaphamust1100
    @mustaphamust1100 3 года назад +1

    VERY NICE VIDEO thank you

  • @deekshakatiyar8380
    @deekshakatiyar8380 3 года назад +1

    Such a good informative video. Please make whole tutorial videos working in excel using python.

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Thank you Deeksha, sure will try to make more video on python with excel.

  • @TomofHelatrobus
    @TomofHelatrobus 3 года назад +1

    I kept getting errors in pycharm due to the deprecated syntax I was using for openpyxl. I couldn't upgrade to the most recent version of openpyxl because I was using the wrong syntax, but couldn't find the correct syntax until I saw it in this video. Thanks for the help!

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Thank you mate I am glad it helped you 👍

  • @basavrajningadali4919
    @basavrajningadali4919 2 года назад +1

    great explanation brother

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      Glad you liked it Thanks Basavraj

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      Glad you liked it Thanks Basavraj

  • @muporepain
    @muporepain 3 года назад +1

    Excellent videos, but without subtitles I don't understand a thing from this accent... Thank you for the video.

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Sorry about that Afrodite , I will try to add subtitles from next videos.

    • @muporepain
      @muporepain 3 года назад

      @@Mukeshotwani Thank you for your reply and for this great effort you make and you explain everything so nice… I hope I didn’t sound mean… :-)

  • @nimanshjain6661
    @nimanshjain6661 2 года назад

    nice video helped me complete my project way faster as using excel helped me a lot I just have a doubt that if I use excel 365 will it work?

  • @umeshmore8251
    @umeshmore8251 3 года назад

    Nice tutorial and very well explained. Thanks 🙏

  • @RoManov99x
    @RoManov99x 2 года назад +1

    Thank you sooo much!

  • @franklegarreta
    @franklegarreta 2 года назад +1

    Great tutorial Mukesh! One question though - You showed how to use Openpyxl Patternfill arguments to Write an Excel cell with solid foreground color but what if you wanted to Read the style of an Excel cell? For example - have python test if a cell is greyed out?

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      Thanks Frank and I am glad you liked it.
      You can check this article for reading cell style newbedev.com/python-openpyxl-how-to-read-a-cell-font-color

    • @franklegarreta
      @franklegarreta 2 года назад

      @@Mukeshotwani Thanks for the info on font color Mukesh, but is it possibly to reliably get the value (preferably in hex) for empty grey filled cells?
      I have tried using the following but with unpredictable results;
      cell_under_test.fill.start_color.index

  • @nabilnabil1824
    @nabilnabil1824 3 года назад

    Thank you , Mukesh

  • @mayanktailor2319
    @mayanktailor2319 3 года назад +2

    If I give large sized value for any excel cell using python (larger than excel column width), and when open excel sheet, I have to adjust excel column width manually. Is there any command in python which auto adjust the excel column width?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hey Mayank openpyxl will help read and write but adjust excel column width have not tried.

  • @akashkoiri4779
    @akashkoiri4779 2 года назад +1

    Thank you so much sir

  • @raviray4660
    @raviray4660 3 года назад +1

    Great video 👍..
    1 ques ,how we use a excel data as a input in our webpage..

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hi Ravi, once you get data in variable then you can use in sendKeys() method

    • @raviray4660
      @raviray4660 3 года назад

      @@Mukeshotwani thanks Mukesh. 😇😇

  • @revanthgowd5744
    @revanthgowd5744 2 года назад

    Thank you the session was usefull 👍

  • @burysandrine6201
    @burysandrine6201 3 года назад +1

    Thank you so much. It was extremely helpful

  • @himanshugupta241
    @himanshugupta241 3 года назад

    Thank you so much sir.

  • @garimad2320
    @garimad2320 3 года назад

    Hi Mukesh - This is amazing source - Thanks for such a great work. Can you please recommend any library to write to xlsb file ?

  • @arjunkatyal1989
    @arjunkatyal1989 3 года назад +1

    Very nice explanation. In detail.
    If possible could you please explain on how to prepare complex graphs in excel using python openpyexcel

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Sure Will try Arjun, in the meanwhile please refer below link for charts and graphs. openpyxl.readthedocs.io/en/stable/charts/introduction.html

    • @arjunkatyal1989
      @arjunkatyal1989 3 года назад

      Ok thank you

  • @divya_yerva8974
    @divya_yerva8974 3 года назад +1

    Thanks sir for your class

  • @Thealonesoldier421
    @Thealonesoldier421 2 года назад

    Hi ..is it possible to create worksheets also ?

  • @nihalrahman8233
    @nihalrahman8233 3 года назад +1

    thnxxxx brother
    it helps

  • @titututus
    @titututus 3 года назад

    Very nice,plz make more video

  • @poornimahanchinal5120
    @poornimahanchinal5120 3 года назад

    It was really a perfectly understandable vedio, but I need a deeper knowledge about checking the colour of a cell of existing excel sheet using python please help me with that sir

  • @Bindu_Ivaturi
    @Bindu_Ivaturi 3 года назад +3

    Thank you for the beautiful video!! Would also like to understand whether is it possible to get some data on condition, like if I want the name of the person where address is India using openpyxl. Thank you!

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Yes you can! we need to map this condition in code.

  • @anilthakkar2372
    @anilthakkar2372 2 года назад

    brother how do we search for a specific string in a list of xlsx files within a folder and print its common list?
    for. e.g. if I want to search string "Accomplished" in all the xlsx files present In a folder called Task.
    would be grateful if u could solve this for me.

  • @ahmedalkassab9751
    @ahmedalkassab9751 3 года назад +1

    thanks :)

  • @saurabhrawal1433
    @saurabhrawal1433 3 года назад +2

    Thank you so much :-)

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      You're welcome! Saurabh. Keep learning.

  • @shubharoy007
    @shubharoy007 3 года назад +1

    How to save multiple entities at the same time using loop?

  • @satydevnegi5454
    @satydevnegi5454 3 года назад +1

    If we have a value in first column and we want to take a value in same row but 5th of 6 th column what coding will be for that

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Satydev coding will be same but you need to change cell number only.

  • @ishwariit
    @ishwariit 3 года назад

    Thanks bro it helped a lot

  • @msinzamam413
    @msinzamam413 2 года назад

    Sir, when i tried.. It showing typeerror string indices must be integers

  • @shreyshrivastava240
    @shreyshrivastava240 3 года назад +1

    Thank you very much

  • @mb26100
    @mb26100 3 года назад +2

    Very well explained. Thank you ! I included the package Openpyxl. tried exactly the same thing but could not get the .value function when I did it. Any reason why would that happen ?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hey Munmun, can you tell me what error did you get when you executed the code?

    • @mb26100
      @mb26100 3 года назад

      @@Mukeshotwani It worked fine. It was a typo. Thank you for your reply !

  • @KishoreKumar-mh4td
    @KishoreKumar-mh4td 3 года назад

    Great! thanks a lot... how to create multiple sheets with different names fed into the cells of each sheet like mail merge from a list.

  • @jacklineodago5100
    @jacklineodago5100 2 года назад

    This video is very helpful. I actually tried but I got a FileNotFoundError and have been wondering where have gone wrong. please any assistance I will appreciate. Thanks

  • @vamseekrishna2389
    @vamseekrishna2389 2 года назад

    Thanks for the very informative video...,
    I have one question when I am counting on the number of rows it gives me the exact number, but sometimes I have merged rows and how to count in such scenario?

  • @pavanbondada1361
    @pavanbondada1361 3 года назад

    nice video .... if we have more sheet for example 5 sheets and we need to change sheetname dynamically how can we do

  • @NagaRaju-se5ov
    @NagaRaju-se5ov 2 года назад

    Hi Mukesh
    I am following ur videos, ur videos are excellent and thanks for ur time.. I need one help on Excel in python.. We may have around 3000 to 4000 scripts in the framework and sometimes more also based on the application that we are automating . Now question is if we want to retrieve 2590 record from excel sheet , it may be take sometime for retrieval right ? Can we consider Excel sheet as database so that data retrieval will be faster and execution wont take much time also. How can we do this scenario in python . Could you please help and Thanks in Advance..

  • @NavjotSinghpatiala
    @NavjotSinghpatiala 3 года назад +1

    when i do this: import openpyxl
    i am getting this Process finished with exit code 0.
    nothing else, colour of the import is also dull or gray

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Navjot, mport openpyxl but until you dont use it will show in gray. Start using openpyxl module so it will change.

  • @jagank4484
    @jagank4484 2 года назад

    Hi Mukesh, Thank you for video, can you please help how to write df to excel sheet, i have df , will be sliced and should be written to different excel sheets based on some condition , can you please help how to do this??. i dont want to write into new excel , i need to load excel template and write to it. Thanks in advance

  • @deepapandey849
    @deepapandey849 2 года назад

    Please help -- Import "openpyxl" could not be resolved from sourcePylance(reportMissingModuleSource), getting these error whenever trying to import openpyxl

  • @gautamgovinda5140
    @gautamgovinda5140 2 года назад +1

    Thanks

  • @dineshbabu-xp1sw
    @dineshbabu-xp1sw 3 года назад

    Hi Sir, I would like to search/find a text in a column and get its cell address/co-ordinates using Openpyxl. Could you please help me on this?

  • @burysandrine6201
    @burysandrine6201 3 года назад +1

    Hello, I am unable to open my excel file on pycharm . I followed every step but it keeps saying file not found error. But I see the file . What could be the problem ?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Bury, can you try opening excel in windows explorer.

  • @mohamedshahidomar3682
    @mohamedshahidomar3682 2 года назад

    Which python package should be used for reading '.xls' format ?

  • @rma3523
    @rma3523 3 года назад

    Thanks sir

  • @nasinabhargavi8108
    @nasinabhargavi8108 3 года назад +1

    Hi Mukesh, How will I add the data to same file. I am getting permission denied error

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hi Nasina, make sure you have read write permissions

  • @AbhishekMishrawillshine
    @AbhishekMishrawillshine 3 года назад

    How do we format entire column.. say a column with date and time in excel and if i want to change it to specific date format then how do i read and write in python?

  • @RashidKhan-tz5ct
    @RashidKhan-tz5ct 2 года назад

    Hi Mukesh, Thanks for the value addition. Please help me in getting the data from cell range like from B2:B17 in an excel sheet.
    Thanks in advance

  • @diyyalao3378
    @diyyalao3378 3 года назад

    I installed openpyxl in pycharm but i am unable to run your code .I am getting errors

  • @nisar_pasha
    @nisar_pasha 2 года назад +1

    Can you please upload reading the excel having formula to a particular cell

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      HI Nisar, please use below
      data_only=True
      Example
      wb = openpyxl.load_workbook(filename, data_only=True)

    • @royalwinautomatedsoftware2985
      @royalwinautomatedsoftware2985 2 года назад

      @@Mukeshotwani hai sir, im using data_only=True . That time automatic remove formula my excel sheet. How solve I keep formula every cell. Please help me

  • @nishavenkatesh7987
    @nishavenkatesh7987 3 года назад

    very good explanation

  • @minalwaman8629
    @minalwaman8629 2 года назад

    Hi .. How to insert data in excel sheet till end of row

  • @naveenkumaranupoju8771
    @naveenkumaranupoju8771 2 года назад +1

    Hi sir can u please explain how to open excel file automatically from any path?

    • @Mukeshotwani
      @Mukeshotwani  2 года назад

      Hi Naveen, what is your use case? openpyxl will open in memory in will read.

  • @patricialamas429
    @patricialamas429 3 года назад +2

    Thanks :)

  • @hardikgujarathi1202
    @hardikgujarathi1202 3 года назад +1

    I created excel file XLSX. through visual studio code only and then trying to open in my folder drive however it is showing error your file extension is not valid and not compatible .i am using excel2010

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hey Hardik, you can cross check excel is valid or not by going to the location.

    • @hardikgujarathi1202
      @hardikgujarathi1202 3 года назад

      @@Mukeshotwani i checked. everything seems perfect.
      Can you share number so i can share on whatsapp

  • @thewanderersolo8069
    @thewanderersolo8069 2 года назад

    i want text boxes description boxes , titles , radio buttons ,check boxes , please help

  • @srikrishnanr8155
    @srikrishnanr8155 3 года назад +1

    Can you please explain if i have a range of cells with formula and i need to paste as values in the same range ie ctrl c the range and alt e s v in excel. How to aarive the same using openpyxl excel kindly help on this

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      You can try with formula openpyxl.readthedocs.io/en/stable/formula.html

    • @srikrishnanr8155
      @srikrishnanr8155 3 года назад

      @@Mukeshotwani Can you please explain how to arrive alt e s v using openpyxl ? As i m having a sheet in cell range with formulas and i need to perfrom copy (ctrl c range of cells, alt e s v ) to paste as values in same range of cells please help to explain how to arrive at this using openpyxl
      github.com/srikrishh23/Sri/blob/main/Multiplesheetformula.py
      ruclips.net/video/lpSax1CY2_g/видео.html
      I dont want to print but need to convert the formulas to values in the same range fo cells

  • @KhalilYasser
    @KhalilYasser 3 года назад +1

    Thank you very much. Clear and perfect explanation. Can you share the code on GitHub?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад +1

      Hi Yasser, here is the code learn-automation.com/how-to-read-and-write-excel-files-in-python-using-openpyxl/

    • @KhalilYasser
      @KhalilYasser 3 года назад

      @@Mukeshotwani Thanks a lot for all these awesome efforts.

  • @dilipdelwash3192
    @dilipdelwash3192 3 года назад

    yes

  • @manikandanv1811
    @manikandanv1811 2 года назад

    Hai bro
    How to pass empty values from excel sheet in DDT testing

  • @pravallikachunduru7116
    @pravallikachunduru7116 3 года назад +1

    Can we read date as how it is displayed in excel sheet

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Pravallika you can read as String.

    • @pravallikachunduru7116
      @pravallikachunduru7116 3 года назад

      @@Mukeshotwani could you suggest how? When I tried to read date in excel as string, it came as 2019-09-19 00:00:00 and $45.89 is read as 45.89. I want to read them as is. Couldn't find anything in python libraries to do that

  • @arkabose89
    @arkabose89 3 года назад +1

    I want to write/update value to a range in sn existing excel worksheet by inputting a dataframe. Is that possible?

    • @Mukeshotwani
      @Mukeshotwani  3 года назад

      Hi Arka never tried this but I guess it can be done check Openpyxl doc openpyxl.readthedocs.io/en/stable/

    • @arkabose89
      @arkabose89 3 года назад

      @@Mukeshotwani yes, by combining pandas and using openpyxl as engine it can be done