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
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
18
app/main.py
18
app/main.py
@@ -490,8 +490,26 @@ async def export_excel(
|
||||
# 3) Excel em memória
|
||||
output = BytesIO()
|
||||
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:
|
||||
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)
|
||||
|
||||
return StreamingResponse(
|
||||
|
||||
Reference in New Issue
Block a user