Python读写Excel
程序员文章站
2024-01-02 09:56:40
读Excel 1 #打开Excek,xlsfile为Excel路径+文件名 2 boorRead = xlrd.open_workbook(xlsfile) 3 #读取sheet,sheet_name为Excel中sheet的名称 4 sheetRead = boorRead.sheet_by_na ......
读excel
1 #打开excek,xlsfile为excel路径+文件名 2 boorread = xlrd.open_workbook(xlsfile) 3 #读取sheet,sheet_name为excel中sheet的名称 4 sheetread = boorread.sheet_by_name(sheet_name) 5 #读取单元格内容 6 data = sheetread.cell_value(row, col)
写excel
1 #创建文件对象 2 wrbook = xlwt.workbook(encoding='utf-8', style_compression=0) 3 #增加sheet 4 wrsheet = wrbook.add_sheet(sheet_name, cell_overwrite_ok=true) 5 #向单元格写数据, 6 wrsheet.write(row,col,data) 7 #保存文件 8 wrbook.save(xlsname)
修改已经存在的excel文件
1 book = xlrd.open_workbook(xlsfile,formatting_info=true) 2 book_wr = copy(book) 3 sheet_wr = bookwr.get_sheet(sheet_name) 4 sheet_wr.write(row,clo,data) 5 book_wr.save(file_name)
详细可参看:https://blog.csdn.net/u013045749/article/details/49910695