import xlrd import json import xlwt class GetJson(object): def __init__(self): self.workbook = xlwt.Workbook(encoding='utf-8') self.sheet = self.workbook.add_sheet('已完成') workfile = xlrd.open_workbook('filedeal.xlsx') table = workfile.sheets()[1] self.data_z = table.col_values(0) self.data_o = table.col_values(1) self.data_t = table.col_values(2) self.data_th = table.col_values(3) self.data_f = table.col_values(4) self.data_fi = table.col_values(5) self.data_s = table.col_values(6) self.data_se = table.col_values(7) def collectData(self): count = 0 num = 0 for data in self.data_f[1:]: num += 1 print(data) data = json.loads(data) print(type(data)) Main = data['Main'] personalPaymentInfo = data['PersonalPaymentInfo'] number = self.data_z[num] user = self.data_o[num] submitTime = self.data_t[num] title = self.data_th[num] checkTime = self.data_fi[num] node = self.data_s[num] checkUser = self.data_se[num] details = self.data['Details'] item = [number,user,submitTime,title,checkTime,node,checkUser,details] for detail in details: count += 1 for idx,ite in enumerate(item): self.sheet.write(count, idx, ite) PaymentDeptName = detail['PaymentDeptName'] CostTypeName = detail['CostTypeName'] StartPosition = detail['StartPosition'] Destination = detail['Destination'] Currency = detail['Currency'] CurrencyDisplayName = detail['CurrencyDisplayName'] Amount = detail['Amount'] CostCenterName = detail['CostCenterName'] Remark = detail['Remark'] AliTripOrderId = detail['AliTripOrderId'] StartDate = detail['StartDate'] EndDate = detail['EndDate'] item = [PaymentDeptName,CostTypeName,StartPosition,Destination,Currency,CurrencyDisplayName,Amount,CostCenterName,Remark,AliTripOrderId ,StartDate,EndDate] num = 11 for idx,ite in enumerate(item): num+=idx self.sheet.write(count, num, PaymentDeptName) self.workbook.save('已完成.xls') myList = [1,4,5,0,6,324,21,4,45,4,54,54,5,4,5,422,] def getMax(oneli): length = len(oneli) for i in range(0,length): for j in range(0,length-i-1): if oneli[j]>oneli[j+1]: tmp = oneli[j] oneli[j] = oneli[j+1] oneli[j+1] = tmp return oneli[length-1] def getJsonData_two(): workbook = xlwt.Workbook(encoding='utf-8') sheet = workbook.add_sheet('已完成') sheet.write(0, 0, '流程编号') sheet.write(0, 1, '提交用户') sheet.write(0, 2, '提交时间') sheet.write(0, 3, '标题') sheet.write(0, 4, '审核日期') sheet.write(0, 5, '审核节点') sheet.write(0, 6, '审核用户') sheet.write(0, 7, 'name') sheet.write(0, 8, 'CompanyName') sheet.write(0, 9, 'DeptmentName') sheet.write(0, 10, 'ReimbursementFor') sheet.write(0, 11, 'PaymentDeptName') sheet.write(0, 12, 'CostTypeName') sheet.write(0, 13, 'StartDate') sheet.write(0, 14, 'EndDate') sheet.write(0, 15, 'StartPosition') sheet.write(0, 16, 'Destination') sheet.write(0, 17, 'Currency') sheet.write(0, 18, 'CurrencyDisplayName') sheet.write(0, 19, 'Amount') sheet.write(0, 20, 'CostCenterName') sheet.write(0, 21, 'Remark') sheet.write(0, 22, 'AliTripOrderId') sheet.write(0, 23, 'Receiver') sheet.write(0, 24, 'BankName') sheet.write(0, 25, 'Account') sheet.write(0, 26, 'OriginalCurrencyTotalAmount') sheet.write(0, 27, 'TotalBalancedAmount') workfile = xlrd.open_workbook('filedeal.xlsx') table = workfile.sheets()[1] data_z = table.col_values(0) data_o = table.col_values(1) data_t = table.col_values(2) data_th = table.col_values(3) data_f = table.col_values(4) data_fi = table.col_values(5) data_s = table.col_values(6) data_se = table.col_values(7) count = 0 num = 0 print(data_f[1]) for data in data_f[1:]: num += 1 print(data) data = json.loads(data) print(type(data)) Main = data['Main'] personalPaymentInfo = data['PersonalPaymentInfo'] number = data_z[num] user = data_o[num] submitTime = data_t[num] title = data_th[num] checkTime = data_fi[num] node = data_s[num] checkUser = data_se[num] details = data['Details'] for detail in details: count += 1 sheet.write(count, 0, number) sheet.write(count, 1, user) sheet.write(count, 2, submitTime) sheet.write(count, 3, title) sheet.write(count, 4, checkTime) sheet.write(count, 5, node) sheet.write(count, 6, checkUser) PaymentDeptName = detail['PaymentDeptName'] CostTypeName = detail['CostTypeName'] StartPosition = detail['StartPosition'] Destination = detail['Destination'] Currency = detail['Currency'] CurrencyDisplayName = detail['CurrencyDisplayName'] Amount = detail['Amount'] CostCenterName = detail['CostCenterName'] Remark = detail['Remark'] AliTripOrderId = detail['AliTripOrderId'] StartDate = detail['StartDate'] EndDate = detail['EndDate'] sheet.write(count, 11, PaymentDeptName) sheet.write(count, 12, CostTypeName) sheet.write(count, 13, StartDate) sheet.write(count, 14, EndDate) sheet.write(count, 15, StartPosition) sheet.write(count, 16, Destination) sheet.write(count, 17, Currency) sheet.write(count, 18, CurrencyDisplayName) sheet.write(count, 19, Amount) sheet.write(count, 20, CostCenterName) sheet.write(count, 21, Remark) sheet.write(count, 22, AliTripOrderId) name = Main['ReimbursementByName'] CompanyName = Main['CompanyName'] DeptmentName = Main['DeptmentName'] ReimbursementFor = Main['ReimbursementFor'] print(name, CompanyName, DeptmentName, ReimbursementFor) sheet.write(count, 7, name) sheet.write(count, 8, CompanyName) sheet.write(count, 9, DeptmentName) sheet.write(count, 10, ReimbursementFor) Receiver = personalPaymentInfo['Receiver'] BankName = personalPaymentInfo['BankName'] Account = personalPaymentInfo['Account'] OriginalCurrencyTotalAmount = personalPaymentInfo['OriginalCurrencyTotalAmount'] TotalBalancedAmount = personalPaymentInfo['TotalBalancedAmount'] print(Account) sheet.write(count, 23, Receiver) sheet.write(count, 24, BankName) sheet.write(count, 25, Account) sheet.write(count, 26, OriginalCurrencyTotalAmount) sheet.write(count, 27, TotalBalancedAmount) workbook.save('已完成.xls')
Json(Excel)处理
猜你喜欢
转载自blog.csdn.net/baidu_32542573/article/details/89350504
今日推荐
周排行