-1
Hello I have a spreadsheet xls
and a XML
where I read this information and my goal is to find information from XMl
inside the spreadsheet for this I am using the method IN
more can not find
THE XML:
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe Id="NFe35200915332149000145550010000190821314695600" versao="4.00">
<ide>
...
</ide>
<emit>
...
</emit>
<dest>
...
</dest>
<autXML>
<CNPJ>15332149000145</CNPJ>
</autXML>
<det nItem="1">
<prod>
<cProd>SL-043210</cProd>
<cEAN>6949999876804</cEAN>
<xProd>KIT ONIX / PRISMA 2020 COM MOLDURA BOTAO MODELO UNIVERSAL</xProd>
<NCM>85122021</NCM>
<CEST>0105500</CEST>
<CFOP>5405</CFOP>
<uCom>PC</uCom>
<qCom>3.0000</qCom>
<vUnCom>300.000000</vUnCom>
<vProd>900.00</vProd>
<cEANTrib>6949999876804</cEANTrib>
<uTrib>PC</uTrib>
<qTrib>3.0000</qTrib>
<vUnTrib>300.000000</vUnTrib>
<indTot>1</indTot>
<xPed>2373</xPed>
</prod>
The spreadsheet:
What I’ve already tried:
import xlrd
import os.path
import sys
import xml.etree.ElementTree as ET
#Bibliotecas
#------------------------------------------------------------------------------------------#
workbook = xlrd.open_workbook(r"C:\Users\Expedição\Videos\CSV\produtos_filtrado.xls") # Escolhe o arquivo a ser lido.
worksheet = workbook.sheet_by_index(0) #Escolha a aba a ser lida.
for i in range(worksheet.nrows): #itere sobre os itens da aba
lista = (worksheet.row(i))
print(lista)
#localiza arquivo,lista todos os itens
#------------------------------------------------------------------------------------------
#XML = input("Coloque o diretorio do XML: ").strip('"')
tree = ET.parse(r"C:\Users\Expedição\Downloads\35200915332149000145550010000190821314695600-nfe.xml")
root = tree.getroot()
ns = {'nfe': 'http://www.portalfiscal.inf.br/nfe'}
for det in root.findall('.//nfe:det', ns):
nItem = det.attrib['nItem']
EAN = det.find('.//nfe:cEAN', ns).text
if EAN in lista:
print("encontrado")
print(EAN)
else:
print("nao achou")
print(EAN)
Is this all your code??? Where are you declaring the variable
lista
?– Juan Caio
the excuse I’ll edit
– user198451