Home > Backend Development > Python Tutorial > Python implements code for reading, writing and modifying Excel

Python implements code for reading, writing and modifying Excel

不言
Release: 2018-09-28 14:21:17
forward
2467 people have browsed it

The content of this article is about the code for reading, writing and modifying Excel in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Read Excel

#打开Excek,xlsfile为Excel路径+文件名
boorRead  = xlrd.open_workbook(xlsfile)
#读取sheet,sheet_name为Excel中sheet的名称
sheetRead = boorRead.sheet_by_name(sheet_name) 
#读取单元格内容
data = sheetRead.cell_value(row, col)
Copy after login

Write Excel

#创建文件对象
wrbook = xlwt.Workbook(encoding='utf-8', style_compression=0)
#增加sheet
wrsheet = wrbook.add_sheet(sheet_name, cell_overwrite_ok=True)
#向单元格写数据,
wrsheet.write(row,col,data)
#保存文件
wrbook.save(xlsname)
Copy after login

Modify an existing Excel file

book = xlrd.open_workbook(xlsfile,formatting_info=True)
book_wr = copy(book)
sheet_wr = bookWr.get_sheet(sheet_name)
sheet_wr.write(row,clo,data)
book_wr.save(file_name)
Copy after login

The above is the detailed content of Python implements code for reading, writing and modifying Excel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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