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

python 读取excel数据插入到另外一个excel

时间:2017-01-12 09:39:15      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:color   print   log   work   div   exce   读取   book   .sh   

#-*-coding:utf-8-*-
import xlrd
import xlwt


def excel_copy(dir_from, dir_to, sheet_name):
    ‘‘‘从一个excel写入到另外一个excel‘‘‘

    wb = xlrd.open_workbook(dir_from)
    # 选择sheet页
    sheet1 = wb.sheet_by_index(0)
    # 打印每个sheet页的行数
    # print("sheet1行数:%d" % sheet1.nrows)
    # 创建写入文件
    workbook = xlwt.Workbook(encoding="ascii")
    # 创建写入sheet页
    worksheet = workbook.add_sheet(sheet_name)
    # 写入excel
    for i in range(0, sheet1.nrows):
        values_row1 = sheet1.row_values(i)
        print(values_row1)
        for s in range(len(values_row1)):
            worksheet.write(i, s, values_row1[s])
    workbook.save(dir_to)

 

python 读取excel数据插入到另外一个excel

标签:color   print   log   work   div   exce   读取   book   .sh   

原文地址:http://www.cnblogs.com/breakcircle/p/6274573.html

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