实例介绍
【实例简介】由出货流水生成单个客户的对账单&合同。
【实例截图】


【核心代码】
# extract_data.py
# -*- coding: utf-8 -*-
# @Date : 2016/5/13 11:04 r_w_006可以写入了。改善记录。
# @Function: 流水中提取有效的出货数据,生成对账单。
# @Author : ThomasBao
'''
2016-5-20
输入:全部流水资料 如 e:20160519.xls
输出:客户出货.xls 客户合同.xls
1.筛选条件:
a客户名称 easygui.enterbox 瑞丰科技,可改客户名称
b合计金额不等于0 有效出货统计
c升级背景色=白色 (64) 未结款的
2016-5-15
增加索引型号
型号排列,对单价相同的型号求和;
'''
import os
import string
import xlrd
import xlwt
import easygui
def handle_data():
#"""处理数据"""
# from datetime import datetime
import time
font0 = xlwt.Font()
font0.name = 'Times New Roman'
font0.colour_index = 2
font0.bold = True
style0 = xlwt.XFStyle() # 默认格式 style0
style0.font = font0
style1 = xlwt.XFStyle() # 日期格式
style1.num_format_str = 'YYYY-MM-DD'
default_file = r'd:/20160509.xls'
input_file = easygui.enterbox(u'输入文件',title = 'please input filename',default ='',strip =False)
file = [default_file,input_file][input_file !='']
# default_custom_name = u'瑞丰科技' # row_input(u'请输入客户名称,如果回车默认清华时代') # 输入客户名称
# input_custom_name = raw_input(u'输入客户名称')
# custom_name = [default_custom_name,input_custom_name][input_custom_name !='']
# print "%s" %custom_name
# filepath = raw_input(u'pleease input the file path')
# filepath = [file,filepath][filepath != '']
default_custom_name = u'瑞丰科技'
input_custom_name = easygui.enterbox(u'输入客户名称')
custom_name = [default_custom_name,input_custom_name][input_custom_name !='']
data = xlrd.open_workbook(file,formatting_info = True)
table = data.sheet_by_index(0)
nrows = table.nrows # 行数
ncols = table.ncols # 列数
bill_file = xlwt.Workbook()
bill_sheet = bill_file.add_sheet(u'对账单'' ' custom_name)
bill_sheet.col(0).width = 2678
bill_sheet.col(1).width = 3999
bill_sheet.col(2).width = 3999
bill_sheet.col(3).width = 1500
bill_sheet.col(4).width = 2666
bill_sheet.col(5).width = 2888
'''
sdsd
'''
# 写入第一行标题
new_row = 0
bill_sheet.write(0,0,u'日期')
bill_sheet.write(0,1,u'型号')
bill_sheet.write(0,2,u'规格')
bill_sheet.write(0,3,u'数量')
bill_sheet.write(0,4,u'单价')
bill_sheet.write(0,5,u'合计')
bill_sheet.write(0,6,u'备注')
new_row = 1
totle_mm = 0
for i in range (1,nrows):
mm = table.cell(i,5).value
xfx = table.cell_xf_index(i,0)
xf = data.xf_list[xfx]
bgx = xf.background.pattern_colour_index
# bgx = table.cell(i,21).value # 以后这里用背景颜色= 黄色 替换 0x0d 黄
# print bgx
totle2 = table.cell(i,14).value
if mm == custom_name and bgx == 64 and totle2 !=0 : # 如果客户名称是所选客户,那么提取客户的资料
bill_sheet.write(new_row,0,table.cell(i,1).value,style1)
bill_sheet.write(new_row,1,table.cell(i,9).value)
bill_sheet.write(new_row,2,table.cell(i,10).value)
bill_sheet.write(new_row,3,table.cell(i,11).value)
bill_sheet.write(new_row,4,table.cell(i,13).value)
bill_sheet.write(new_row,5,table.cell(i,14).value)
bill_sheet.write(new_row,6,table.cell(i,5).value)
new_row =1
totle_mm = table.cell(i,11).value
# print bill_sheet.cell(new_row,5).value.encode('utf-8')
#print u'采集有效样机单数%d 合计数量 %d 个' %new_row %totle_mm
print (u'采集有效出货 合计数量 %d 个' %totle_mm)
bill_file.save(u'd:/' custom_name u'出货.xls');
print (u'出货' custom_name 'extract ok')
file = u'd:/' custom_name u'出货.xls'
data = xlrd.open_workbook(file,formatting_info = True)
table = data.sheet_by_index(0)
nrows = table.nrows # 行数
ncols = table.ncols # 列数
# 打开客户型号
if custom_name == u'清华时代' :
model = custom_name
else:
model = u'常规'
file2 = u'd:/' model u'型号.xls' #打开客户型号
data2 = xlrd.open_workbook(file2,formatting_info = True)
table2 = data2.sheet_by_index(0)
nrows2 = table2.nrows # 行数
ncols2 = table2.ncols
# 由出货记录生产对账合同。
list_products=[]
list_products.append(u'型号')
list_num = 1
for i in range(0,nrows): #扫描出货记录中所有型号
for j in range (0,list_num): #查询列表 中的型号与 出货记录有没有重复;
mm = list_products[j] #提取产品型号mm
tt = table.cell(i,1).value
if mm !=tt:
print (u'不同')
continue
else:
print (u'找到')
break
print (tt)
if mm !=tt:
list_products.append(tt)
list_num =1
list_products.sort()
print ('****************')
constact_file = xlwt.Workbook() #写合同
constact_sheet = constact_file.add_sheet(u'合同 ' custom_name)
constact_sheet.col(0).width = 2678
constact_sheet.col(1).width = 3999
constact_sheet.col(2).width = 3999
constact_sheet.col(3).width = 1500
return None
def main():
handle_data()
if __name__ == '__main__':
main()
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论