python excel 读写
Posted qukaige
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python excel 读写相关的知识,希望对你有一定的参考价值。
excel 读取
import openpyxl import xlwt
data = xlrd.open_workbook("C:/Users/4YUJIAN/Desktop/优惠备案.xls") table = data.sheets()[0] nrows = table.nrows #行数 ncols = table.ncols #列数 for i in range(nrows): r = table.row_values(i) # 某一行数据 print(r)
excel 写
def write07Excel(path, value, fileName): wb = openpyxl.Workbook() sheet = wb.active sheet.title = fileName for i in range(len(value)): for j in range(len(value[i])): sheet.cell(row=i + 1, column=j + 1, value=str(value[i][j])) wb.save(path) print("写入数据成功!") def write03Excel(path, value, fileName): wb = xlwt.Workbook() sheet = wb.add_sheet(fileName) for i in range(len(value)): for j in range(len(value[i])): v = str(value[i][j]) sheet.write(i, j, v) wb.save(path) print("写入数据成功!")
数据传入格式 :
[(1,2,3)] # 行列 [[2,3,4]]
以上是关于python excel 读写的主要内容,如果未能解决你的问题,请参考以下文章