Quatro casas decimais ao gerar o excel para os campos ICMS (%), ICMS (%) (UF/Ref), Dif. ICMS (pp), PIS (%), COFINS (%)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-08-13 21:51:49 -03:00
parent fb08efed1d
commit e6c0155758

View File

@@ -490,8 +490,26 @@ async def export_excel(
# 3) Excel em memória # 3) Excel em memória
output = BytesIO() output = BytesIO()
df = pd.DataFrame(dados) df = pd.DataFrame(dados)
# garante que colunas percentuais estejam numéricas (se existirem)
for col in ["ICMS (%)", "ICMS (%) (UF/Ref)", "Dif. ICMS (pp)", "PIS (%)", "COFINS (%)"]:
if col in df.columns:
df[col] = pd.to_numeric(df[col], errors="coerce")
with pd.ExcelWriter(output, engine="xlsxwriter") as writer: with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
df.to_excel(writer, index=False, sheet_name="Relatório") df.to_excel(writer, index=False, sheet_name="Relatório")
# aplica formatação 4 casas decimais
wb = writer.book
ws = writer.sheets["Relatório"]
fmt_4dec = wb.add_format({"num_format": "0.0000"})
for col in ["ICMS (%)", "ICMS (%) (UF/Ref)", "Dif. ICMS (pp)", "PIS (%)", "COFINS (%)"]:
if col in df.columns:
i = df.columns.get_loc(col)
# largura automática básica + formato; ajuste a largura se quiser (ex.: 12)
ws.set_column(i, i, None, fmt_4dec)
output.seek(0) output.seek(0)
return StreamingResponse( return StreamingResponse(