因为工作中需要用到,故备份一份随机代码,没有解释,仅供自己参考

#!/user/bin/env python
# encoding: utf-8
import sys
import time
import urllib
import urllib3
import requests
import xlrd
import xlwt
from xlutils.copy import copy



def readExcel():
    wb_add=xlrd.open_workbook_xls(r'files/add.xls',formatting_info=True)
    wb_ori=xlrd.open_workbook_xls(r'test.xls',formatting_info=True)
    '''
    读取excel文件数据,并逐行填写空白部分
    '''
    #一、获取待写入工作表对象
    work_sheet_add=wb_add.sheet_by_index(0)
    work_sheet_ori=wb_ori.sheet_by_index(0)


    #三、循环打印


    #写入数据
    excel = copy(wb_ori)
    sheet = excel.get_sheet(0)
    for j in range(73):
        sheet.write(j+3,50, work_sheet_add.cell_value(j+1,16))
    excel.save('test.xls')



    '''
    Workbook类初始化时有encoding和style_compression参数
    encoding:设置字符编码,一般要这样设置:w = Workbook(encoding='utf-8'),就可以在excel中输出中文了。默认是ascii。
    style_compression:表示是否压缩,不常用。
    '''






if __name__ =='__main__':
    readExcel()

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐