2

a very straightforward task in VBA but am not sure how do I perform in python. Hypothetically if I have an excel called 'excel.xlsm', tab name is 'tabA' and I want to insert a value in cell D15, how do I do that in python?

7
  • This question has a lot of answers if searched on Google. Please do some research before asking on SO community. Commented Apr 20, 2020 at 13:36
  • Does this answer your question? Insert row into Excel spreadsheet using openpyxl in Python Commented Apr 20, 2020 at 13:37
  • @Mayank Porwal - thanks mate that was useful as well. Commented Apr 20, 2020 at 14:00
  • 1
    @Abhay salvi - never heard of google, can you send me the link plz! Commented Apr 20, 2020 at 14:01
  • 1
    @Abhaysalvi - thanks ! Commented Apr 20, 2020 at 15:50

2 Answers 2

3

You need a library called openpyxl for that:

import openpyxl

workbook=openpyxls.load_workbook(path)
worksheet= workbook.get_sheet_by_name('tabA')
worksheet['D15']='Whatever you want to put in D15'

Enjoy and read up on openpyxl for more info.

Sign up to request clarification or add additional context in comments.

Comments

0

I couldn't edit Tomfus's answer. To save you excel file after changes you made (otherwise you won't see updates in file). Run workbook.save('file path of your excel')

NOT: File path could be same file path/name that you used to open if you don't want to create copy. It will overwrite automatically

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.