'Print values from a spreadsheet with certain value in column
I'm developing an application to automate a task in the office where I work. It consists of accessing a spreadsheet with customer data and checking which tax needs to be sent to the customer.
After the code, name, national registration code, e-mail and customer taxation come the taxes, according to the spreadsheet model below;
If the x is marked in the tax column (in the case of the code below, the column F:DAS) then I take the data of that customer and put it in a named list integrantes.
The problem I'm facing is that at the time of a simple print to be able to return all the members of the list it returns multiple results and not just the ones with the x. Can you help me?
Follow code below:
import openpyxl
wb = openpyxl.load_workbook('C:/temp/fechamento.xlsx')
sheet = wb['fechamento']
lastCol = sheet.max_column
integrantes = {}
codigos = []
nomes = []
cnpjs = []
emails = []
tributacoes = []
das = []
for r in range(1, sheet.max_row + 1):
for c in range(6, lastCol + 1):
imposto1 = sheet.cell(row=r, column=c).value
if imposto1 != 'x' or '':
codigo = sheet.cell(row=r, column=1).value
nome = sheet.cell(row=r, column=2).value
cnpj = sheet.cell(row=r, column=3).value
email = sheet.cell(row=r, column=4).value
tributacao = sheet.cell(row=r, column=5).value
das1 = sheet.cell(row=1, column=c).value
codigos.append(codigo)
nomes.append(nome)
cnpjs.append(cnpj)
emails.append(email)
tributacoes.append(tributacao)
das.append(das1)
integrantes[nome] = email
for codigo, nome, cnpj, email, tributacao, das1 in zip(codigos, nomes, cnpjs, emails, tributacoes, das):
print(codigo, nome, cnpj, email, tributacao)
Solution 1:[1]
in your if statement, you have
if imposto1 != 'x' or '':
if you are just trying to get the ones with x, it should just be x.
Also you say integrantes is a named list, but you have it defined as a dictionary because of the {}.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Evan Jaksha |
