- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Writing to an excel file using openpyxl module
Openpyxl is a Python library for reading and writing Excel (with extension xlsx/xlsm/xltx/xltm) files. The openpyxl module allows Python program to read and modify Excel files.
For example, user might have to go through thousands of rows and pick out few handful information to make small changes based on some criteria. Using Openpyxl module, these tasks can be done very efficiently and easily.
# import openpyxl module import openpyxl #Call a Workbook() func of openpyxl to create a new blank Workbook object wb = openpyxl.Workbook() # Get workbook active sheet from the active attribute sheet = wb.active # Cell objects also have row, column and coordinate attributes that provide # location information for the cell. # The first row or column integer is 1, not 0. Cell object is created by # using sheet object's cell() method. c1 = sheet.cell(row = 1, column = 1) # writing values to cells c1.value = "Vishesh" c2 = sheet.cell(row= 1 , column = 2) c2.value = "Ved" #Once have a Worksheet object,one can access a cell object by its name also # A2 means column = 1 & row = 2. c3 = sheet['A2'] c3.value = "Python" # B2 means column = 2 & row = 2. c4 = sheet['B2'] c4.value = "Programming" #Anytime you modify the Workbook object or its sheets and cells, the #spreadsheet file will not be saved until you call the #save()workbook method. wb.save("C:\Users\Vishesh\Desktop\demo.xlsx")
- Read and Write to an excel file using Python openpyxl module
- Reading and writing Excel files using the openpyxl module in Python
- Python - Plotting charts in excel sheet using openpyxl module
- Arithmetic operations in excel file using openpyxl in Python
- How to create charts in excel using Python with openpyxl?
- Create and write on excel file using xlsxwriter module in Python
- How to open an Excel file with PHPExcel for both reading and writing?
- Adding a Chartsheet in an excel sheet using Python XlsxWriter module
- Python - Plotting an Excel chart with Gradient fills using XlsxWriter module
- Reading and Writing CSV File using Python
- Python - Plotting an Excel chart with pattern fills in column using XlsxWriter module
- Python - Plotting Area charts in excel sheet using XlsxWriter module
- Python - Plotting bar charts in excel sheet using XlsxWriter module
- Python - Plotting column charts in excel sheet using XlsxWriter module
- Python - Plotting Combined charts in excel sheet using XlsxWriter module