I have been searching for a solution for this issue everywhere and cannot find an answer.
In my workflow, I am passing 2 files (full paths and file names) to a Python Tool as First One and Second One, and then I want to move 3 tabs from First One to Second One, replacing the tabs with that name in Second One.
I am getting AlteryxEngine not defined, and I have tried all the below to get the engine function:
From ayx import Alteryx
engine = Alteryx.get_engine()
Or
From ayx import Alteryx
engine = Alteryx.engine()
Or
From ayx import Package
engine = Package.Engine
I am using this code:
from ayx import Alteryx
import pandas as pd
from openpyxl import load_workbook
import os
engine = Alteryx.get_engine()
# Get file paths from workflow variables
first_file = AlteryxEngine.WorkflowVariables["First One"]
second_file = AlteryxEngine.WorkflowVariables["Second One"]
# Define the sheet names to move
sheets_to_move = ["3E Load File", "Excel Format", "Detail"]
# Read the specified sheets from the first file
sheets_data = pd.read_excel(first_file, sheet_name=sheets_to_move, engine="openpyxl")
# Check if the second file exists
if os.path.exists(second_file):
# Load existing workbook
writer = pd.ExcelWriter(second_file, engine="openpyxl", mode="a",
if_sheet_exists="replace")
else:
# Create a new workbook
writer = pd.ExcelWriter(second_file, engine="openpyxl")
# Write each sheet to the second file
for sheet_name, df in sheets_data.items():
df.to_excel(writer, sheet_name=sheet_name, index=False)
# Save changes
writer.close()
Any Python whizzes see what change(s) I need to make?