码迷,mamicode.com
首页 > 编程语言 > 详细

python excel 读写

时间:2018-12-18 12:17:36      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:filename   value   range   imp   nbsp   title   python   excel   work   

 

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 读写

标签:filename   value   range   imp   nbsp   title   python   excel   work   

原文地址:https://www.cnblogs.com/412013cl/p/10135961.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!