Home >Backend Development >Python Tutorial >Python implements code for reading, writing and modifying Excel
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)
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)
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)
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!