How to read and write excel in python

藏色散人
Release: 2019-10-02 17:29:10
Original
5513 people have browsed it

How to read and write excel in python

How to read and write excel in python?

Python reads the contents of the excel table

1 The first step is to take a look at the contents of the excel table. This table is placed in the root directory of the d drive , the path is d://1.xlsx, as shown in the figure below:

How to read and write excel in python

2 The second step is to enter the

“
import xlrd        
      datas = xlrd.open_workbook('d://1.xlsx')    
table = datas.sheets()[0]    
print(table.nrows)           
print(table.ncols)         
print(table.row_values(0))    
print(table.col_values(0))   
print(table.cell(0,0).value)
”
Copy after login

code in python to proceed Read the contents of the excel table, as shown in the figure below:

How to read and write excel in python

3 The third step is to run the py file. You can see that the contents of the first row and column of the excel table have been read. , as shown in the figure below:

How to read and write excel in python

python writes the content into the excel table

The first step is to enter

“
import xlwt                 
          wb = xlwt.Workbook(encoding='ascii')  
ws = wb.add_sheet('wg')             
 ws.write(0, 0, label='hs')        
ws.write(0, 1, label='wd')        
ws.write(1, 0, label='你好啊')
wb.save('d://xt.xls')           
”
Copy after login

Code, write the content into the xt.xls table, as shown in the figure below:

How to read and write excel in python

2 In the second step, run the py file, and you can see that xt.xls is generated on the d drive When you open the form, you can see that the content has been written in, as shown below:

How to read and write excel in python

Push: "Python Tutorial"

The above is the detailed content of How to read and write excel in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template