Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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"

 coulumns {max_column}  

")
    print(f"

 rows{max_row}  

")
    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)
Comment

PREVIOUS NEXT
Code Example
Python :: code folding vim python 
Python :: fibinacci python 
Python :: Selecting subset of columns with pandas 
Python :: python start process in background and get pid 
Python :: 2d array in python 
Python :: pip install opencv 
Python :: np.random.exponential 
Python :: form action in django 
Python :: image resize in python 
Python :: python remove duplicates from list of dict 
Python :: change the number in 3rd line to get factorial for the number you want. Ex: num = 30 
Python :: time in regression expression python 
Python :: add list to end of list python 
Python :: test with python 
Python :: python if elif else 
Python :: run a python script from another python script on a raspberry pi 
Python :: valid parentheses 
Python :: run multiple test cases pytest 
Python :: open url from ipywidgets 
Python :: reading the JSON from a JSON file 
Python :: is in python 
Python :: remove file os python 
Python :: get all different element of both list python 
Python :: regex find email address in string python 
Python :: create python executable 
Python :: Read the entire text file using the read() function 
Python :: sortedcontainers sorteddict import 
Python :: why a Python Arithmetic Operators used 
Python :: lable on graph in matplotlib 
Python :: indexing python first and last 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =