首页 > 编程语言 > 详细

python读写Excel数据(xlwt,xlrd,xlutils写入数据到已存在的Excel表格中)

时间:2021-09-16 17:08:41      阅读:39      评论:0      收藏:0      [点我收藏+]

一、用到的库:xlwt,xlrd,xlutils

 

二、通过xlrd读取Excel数据:

import xlrd

# 通过open_workbook读取Excel文件
data_r = xlrd.open_workbook("资产盘点记录表.xls")
#通过索引将sheet表赋值给变量 table_r = data_r.sheets()[0]
#获取整列数据(列索引) col_value = table_r.col_values(1)
#获取整行数据(行索引) row_valu e= table_r.row_values(1)
#获取单个单元格数据(行索引,列索引) value = sheet1.cell(1,2).value

三、通过xlwt创建新表写入数据

 

import xlwt
#
创建Excel文件对象、表格页sheet workbook = xlwt.Workbook(encoding=utf-8) worksheet = workbook.add_sheet(sheet名称) # sheet页中写入数据 worksheet.write(0, 0, label=ID) worksheet.write(0, 1, label=姓名) # 保存Excel文件 workbook.save(file_name)

四、通过xlutils在已有表中写数据

 

import xlrd,xlwt
from xlutils.copy import copy

# 将已存在的Excel表格赋值给变量
excel_file = xlrd.open_workbook("准备导入的资产.xls")
# 复制Excel excel_file_copy= copy(data_w2)
# 根据索引获取要写入数据sheet sheet_index = excel_file_copy.get_sheet(0)
# 写入数据 sheet_index.write(1, 2, "张三")
# 保存文件 excel_file_copy.save(准备导入的资产.xls)

 

python读写Excel数据(xlwt,xlrd,xlutils写入数据到已存在的Excel表格中)

原文:https://www.cnblogs.com/zhuomou/p/15266868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!