标题:萌新求教,Typeerror: descriptor 'decode' requires a 'bytes' object but ...
取消只看楼主
irontooth
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-8-20
结帖率:0
已结贴  问题点数:20 回复次数:0 
萌新求教,Typeerror: descriptor 'decode' requires a 'bytes' object but received a 'No
程序如下,想将一个excel里的部分列导入另一个excel中,运行到保存时,总提示Typeerror。请各位大神指点。excel和程序见附件。谢谢!
test.rar (59.69 KB)


# coding=gbk
import xlrd
import xlwt
import time
import xlutils
from xlutils.copy import copy

#打开BM单excel wb_BM
wb_BM = xlrd.open_workbook(r'BM单.xlsx')

#打开BM单sheet st_BM
st_BM = wb_BM.sheet_by_name('数据')

#读入BM数量bmsl
bmsl = st_BM.nrows
print('BM单数量')
print(bmsl)

#读入A列BM单号BM
BM = st_BM.col_values(0)
#读入C列审批状态 SPZT
SPZT = st_BM.col_values(2)
#读入O列需求人 XQR
XQR = st_BM.col_values(14)
#读入S列标题 BT
BT = st_BM.col_values(18)
#-----------------------------------------------------------------------------

#打开备件跟踪excel wb_BJGZ
filename = r'1.xls'
wb_BJGZ = xlrd.open_workbook(filename,formatting_info=True)
#wb_BJGZ = openpyxl.load_workbook(filename)

#打开备件跟踪sheet st_BJGZ
st_BJGZ = wb_BJGZ.sheet_by_name('备件')
#st_BJGZ = wb_BJGZ.get_sheet_names('备件')

wb_BJGZ_Temp = copy(wb_BJGZ)
st_BJGZ_Temp = wb_BJGZ_Temp.get_sheet('备件')


#读入A列序号XH
XH = st_BJGZ.col_values(0)
#读入B列提单备件信息 BJXX  即备件品牌
BJXX = st_BJGZ.col_values(1)
#读入C列提单人 TDR
TDR = st_BJGZ.col_values(2)
#读入G列形成EBM单时间 EBMSJ
EBMSJ = st_BJGZ.col_values(6)
#读入I列形成BM单号 BMDH
BMDH = st_BJGZ.col_values(8)

#读入BM单数量bjbm
bjbm = len(XH)
print('备件BM单数')
print(bjbm)

#-----------------------------------------------------------------------------

#开始比较BM单号
print(BMDH[bjbm-1])

i = 0
k = bjbm
print(k)

while i < bmsl:
    l = 0
    while l < bjbm:
        if BMDH[l] == BM[i]:
            i = i+1
            break
        elif l == bjbm-1:
            #把信息写入BJGZ表#
            print(i)
            st_BJGZ_Temp.write(k,0,k-1)#序号
            st_BJGZ_Temp.write(k,1,BT[i]) #提单备件信息
            st_BJGZ_Temp.write(k,2,XQR[i]) #提单人
            #st_BJGZ_Temp.write(k,6,time.strftime('%Y.%m.%d',time.localtime(time.time()))) #形成EBM时间
            st_BJGZ_Temp.write(k,8,BM[i]) #BM单号
            k = k+1
            l = l+1
        else:
            l = l+1
    i = i+1   
        


#保存检查结果
wb_BJGZ_Temp.save(filename)   

while(True):
    a = input('输入q退出\n')
    if( a == 'q' or a == 'Q'):
        break


搜索更多相关主题的帖子: excel time 读入 print write 
2019-08-20 23:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-496487-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018843 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved