python读写excel文件
来源:互联网 发布:淘宝买csgo怎么下载 编辑:程序博客网 时间:2024/05/19 13:18
安装xlrd、xlwt、xlutils
#coding=utf-8import xlrd import xlwt; import sys, getoptfrom xlutils.copy import copy; class Excel: def __init__(self,fileName): self.bookold = xlrd.open_workbook(fileName) self.book=copy(self.bookold) def insert_merchant_number(self): sheet=self.bookold.sheet_by_index(0) nrows = sheet.nrows ncols = sheet.ncols sheetnew=self.book.get_sheet(0); cnt=0 flag=0 merchant_number="" for r in range(0,nrows-1): cellvalue=sheet.cell_value(r,0) if cellvalue==u"特约单位编号/部门编号:": merchant_number=sheet.cell_value(r,1) merchant_number=int(merchant_number) merchant_number=str(merchant_number) print u"商户号"+merchant_number flag=1 if flag==1 and cellvalue!=u"特约单位编号/部门编号:" and cellvalue!=u"特约单位合计": mer=sheet.cell_value(r,0) mer=int(mer) print "value "+str(mer) #mer=str(mer) mer=str(merchant_number) info=u"写入数据: " print info+mer sheetnew.write(r,0,mer); if cellvalue==u"特约单位合计": flag=0 def save_excle_file(self,fileName): self.book.save(fileName)def main(): opts, args = getopt.getopt(sys.argv[1:], "hi:o:",["ifile=","ofile="]) input_file="" output_file="" mer="" for op, value in opts: if op == "-i": input_file = value elif op == "-o": output_file = value elif op == "-h": sys.exit() excel=Excel(input_file) excel.insert_merchant_number() excel.save_excle_file(output_file)if __name__=="__main__": main()
代码例子
阅读全文
0 0
- python读写Excel文件
- python读写excel文件
- Python读写excel文件
- Python 读写Excel文件
- python读写excel文件
- Python读写excel文件
- python读写Excel文件
- Python读写excel文件
- python读写excel文件
- python读写excel文件
- python读写excel文件
- python 操作excel 读写文件
- 用Python读写Excel文件
- 用Python读写Excel文件
- 用Python读写Excel文件
- 用Python读写Excel文件
- python-23-读写excel文件
- python之读写excel文件
- Maven工程运行报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- WPF Virtualizing Panel
- basic
- 创意族贺小米七周年庆专题:国际“米淘”热潮
- Picture
- python读写excel文件
- php数组根据某一个键值,把相同键值的合并生成一个新的二维数组
- 使用linq.js操作后台JSON数据到前台select标签
- (优先队列)2506完美网络
- FFmpeg X264 H264编码指南[译]
- 点击锚点不到顶部,向下偏移一段距离
- 阿里云首席安全科学家吴翰清的思考:弹性安全网络,构建下一代安全的互联网
- Android studio中.9图片的含义及制作教程
- POJ-3186-Treats for the Cows