Answers for "update excel file with python"

0

change value in excel using python

from xlrd import open_workbook
from xlutils.copy import copy

xl_file = r'D:pathexcel.xls'
rb = open_workbook(xl_file, formatting_info=True)
wb = copy(rb)
sheet = wb.get_sheet(0)
sheet.write(0,2,'New_Data_For_Cell')
wb.save(xl_file)
Posted by: Guest on May-18-2020
1

update xls file using python

"""
Enter the following command `sudo pip install openpyxl
if this doesn't work download openpyxl zip file from 
https://pypi.org/project/openpyxl/
after that extract it and then open the folder in terminal and write 
`sudo python setup.py install`

""""
import openpyxl
try:
    path = "pathOfxlsFile/filename.xls"
    wb_obj = openpyxl.load_workbook(path.strip())
    # from the active attribute
    sheet_obj = wb_obj.active
    # get max column count
    max_column = sheet_obj.max_column
    max_row = sheet_obj.max_row
    print(f"nn coulumns {max_column}  nn")
    print(f"nn rows{max_row}  nn")
    for j in range(1,max_row):
        #count starts form 1, don't use 0 
    	cellThatIsToBeChanged = sheet_obj.cell(row=j, column=1)
       	cellThatIsToBeChanged.value = 'new modified value'
        wb_obj.save('fileName.xlsx')
    except Exception as e:
        print(e)
Posted by: Guest on April-27-2021

Code answers related to "update excel file with python"

Python Answers by Framework

Browse Popular Code Answers by Language