Problems with win32com

Asked

Viewed 293 times

0

I have the following error in my code, I’ve tried everything and I can’t fix:

1° Attempt - Unsuccessful

excel = win32com.client.Dispatch("Excel.Application")
wb = excel.Workbooks.Open(os.path.join(os.getcwd(),diretorio_BKP + filename +
                          '  '+str(nome_arq_parcial)+' -.xlsx'))
ws = wb.Worksheets(1).Select()
ws = wb.Worksheets(1)
print('abrir o arquivo de novo')

2° Attempt - Unsuccessful

excel = win32com.client.Dispatch("Excel.Application")
wb = excel.Workbooks.Open(diretorio_BKP + filename +'  '+
                          str(nome_arq_parcial)+' -.xlsx')
ws = wb.Worksheets(1).Select()
ws = wb.Worksheets(1)
print('abrir o arquivo de novo')

The two attempts return me the following problem:

ERRO:    (-2147352567, 'Exceção.', (0, 'Microsoft Excel', "O Microsoft Excel não
pode acessar o arquivo '\\\\IEMEN\\local do arquivo -.xlsx'. Há várias razões
possíveis: \r\n\r\n• O nome do arquivo ou caminho não existe.\r\n• O arquivo está 
sendo usado por outro programa.\r\n• A pasta de trabalho que você está tentando 
salvar tem o mesmo nome de outra \r\npasta de trabalho aberta no momento.", 
'xlmain11.chm', 0, -2146827284), None)

As you can see already tried to leave in absolute path, already tried to leave the complete fixed path, already put excel.Application.Quit() before this stretch also and nothing.

I need the code to go through this step to start formatting the entire file.

  • Vo just happened to be trying to open an xlsx file. (a spreadsheet.)?

  • Yes and no... I need windows to open to continue formatting code, this problem occurs within the installed Service.

1 answer

0


SOLUTION! INCREDIBLE AS IT MAY SEEM:

I could not believe how obscure this error was and we found the solution looking for similar problems with the equivalent code of . NET:

To fix, create a folder named 'Desktop' in 'C: Windows Syswow64 config systemprofile ' on 64-bit architecture or 'C: Windows System32 config systemprofile ' on 32-bit servers.

WORKED PERFECTLY.

(Source: Stackoverflow replies in English: https://stackoverflow.com/questions/17177612/excel-access-denied-with-win32-python-pywin32)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.