Xlwings python library does not work in uipath

Hello guys, my invoke python method dont works when i use the library xlwings, but when comment the script run.

This way the script runs perfectly in vscode but not when called in studio

import pandas as pd
import xlwings as xw
import json

def ContarLinhas(filePath,sheet,collumn):

    nlinhas = pd.read_excel(filePath, sheet_name=sheet, usecols=[collumn])
    output = len(nlinhas.dropna()) + 2

    return output

def add_dataframe_to_sheet(file_path, sheet_name, df):
    #data = json.loads(js)
    #df = pd.DataFrame(data)
    # Abre o arquivo Excel
    app = xw.App(visible=False)
    workbook = xw.Book(file_path)
    
    # Seleciona a sheet específica
    if sheet_name in [sheet.name for sheet in workbook.sheets]:
        sheet = workbook.sheets[sheet_name]
    else:
        raise ValueError(f"A sheet '{sheet_name}' não existe no arquivo.")

    # Encontra a próxima linha vazia
    last_row = sheet.range('A1').end('down').row
    next_row = last_row + 1 if last_row != 1 else 1

    # Adiciona os novos dados do DataFrame
    for i, row in df.iterrows():
        for j, value in enumerate(row):
            cell = sheet.cells(next_row + i, j + 1)
            cell.value = value

    # Salva o arquivo com as mudanças
    workbook.save(file_path)
    workbook.close()
    app.quit()


# Criação de um DataFrame de exemplo
data = {
    'A': [1, 2],
    'B': [3, 4],
    'C': [5, 6],
    'D': ["=VLOOKUP(G6,'plan CSC'!A:B,2,)", "=VLOOKUP(G7,'plan CSC'!A:B,2,)"]  # Fórmulas VLOOKUP (PROCV em inglês)
}
df = pd.DataFrame(data)

# Exemplo de uso
file_path = 'C:\\Users\\kina_\\OneDrive\\Documentos\\UiPath\\domicilio-bancario\\bot\\DEPOSITOS RECEBIDOS2.xlsx'  # Use string bruta para evitar erros de escape
sheet_name = 'FLUXO'

add_dataframe_to_sheet(file_path, sheet_name, df)
#ContarLinhas(file_path, sheet_name, 3)

when i comment import xlwings the script runs in UiPath but only the method “Contar Linhas”

The library is installed

@victor_kina,

Welcome to the UiPath Community :tada:

Is your Python Scope activity properly configured and able to run any simple script?

Thanks,
Ashok :slight_smile:

Yes, i try to run this code without the library xlwings and works normally

Thanks for the help guys, i change my code to dont use this library.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.