Bootstrap

python xlwt xlrd 写入一行_python读写excel(xlrd,xlwd)

用python读写excel需要导入xlrd(读),xlwd(写)模块:

前提准备:

1.先pip安装xlrd : >>pip install xlrd

pip安装xlwt : >>pip install xlwt

xlrd:

2.xlrd :下面是我写的一个读取excel的类

excel表:

96c67dad2bb7?tdsourcetag=s_pcqq_aiomsg

image.png

运行结果:

96c67dad2bb7?tdsourcetag=s_pcqq_aiomsg

image.png

import xlrd

import os

class ExcelReade(object):

def __init__(self, excel_name, sheet_name):

"""

# 我把excel放在工程包的data文件夹中:

# 1.需要先获取到工程文件的地址

# 2.再找到excel的文件地址(比写死的绝对路径灵活)

os.path.relpath(__file__)

1.根据系统获取绝对路径

2.会根据电脑系统自动匹配路径&#x

;