Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Create/ Edit a Excel File using Python Tool

Nuno_Meneses
7 - Meteor

Hello guys,

 

I have a couple of working python scripts to format excel that is working fine in VS. When I try to run them in alteryx python tool the excel files always get corrupted. 

21.png

 

I tried to run it on Alteryx version 2024.1 and 2023.1 and the results are the same. Your help would be very appreciated!

 

Thank you

import openpyxl

# Make a new notebook (workbook)
workbook = openpyxl.Workbook()

# Open a page (sheet) in the notebook
sheet = workbook.active

# Write something on the page
sheet['A1'] = 'Hello'
sheet['B1'] = 'World'

# Save your notebook with a special name
workbook.save(PATH)

8 REPLIES 8
apathetichell
18 - Pollux

Do you have other tools in your Alteryx workflow?

Nuno_Meneses
7 - Meteor

@apathetichell yes I do, but I have just tried in a new workflow with only python tool I got the same result

 

Edit: I also tried in one drive and in my local machine

apathetichell
18 - Pollux

are you passing in anything to your python (like a path)?

Nuno_Meneses
7 - Meteor

@apathetichell I am just using a single python tool. it is frustrating because all my codes run on Visual Studio but on Alteryx they corrupt excel files.

 

If you mind testing, just change the path on the last line of code

thank you!

apathetichell
18 - Pollux

I'm on 2021.4 and successfully ran this with no errors. my next suggestion would be to try deleting the file and re-running? I have AMP on while running - which I never do - and it still created the file successfully.

 

One note - I ran this with Alteryx in admin mode (primarily to make sure the packages were successfully created in the pip install)...

Nuno_Meneses
7 - Meteor

@apathetichell Did your excel file get corrupted when you open it?

apathetichell
18 - Pollux

No. It was fine. 

 

Question - are you publishing to Users - or your User name subfolder? Do you have any special characters/accents in your name?

Nuno_Meneses
7 - Meteor

I was getting this error using both pandas and openpyxl to create/edit an excel file. I upgraded the version of these libraries and the problem is solved.

 

@apathetichell Thank you for your help!

Labels