Hi Everyone,
Is it possible to use the data from an Alteryx Table Tool and include that information in a DOCX template? I am referring to the use case where Python would also be used.
I think that such a solution might not work, and someone would need to recreate the entire DOCX template in Python. Am I correct?
I'm going with a "this is totally possible" answer. Here are my caveats:
I've never done this. I use Word incredibly sparingly. I use Python only when I have to. You may need to create a temporary html file via render - and use that as your input vs the html report snippet produced via table tool. (you might be able to use table tool as well - but you'd probably have to use plotly or something to format/correct it).
Can you do it off of the full html produced by Render?
I haven't used the table tool and im not sure if this would help in your case but it might. I have used the python tool to read data from incoming alteryx stream and used the shutil package to create copies of a template file, naming the files based on the values in the alteryx data and adding it to a combination to check and avoid making duplicate files. We send out automated emails every week to vendors using a specific template and this creates each file for us to send weekly.
Once the template file copies are made, you then hard key the full path with formula tool in the data based on the condition you named that file in the python code(our case was the unique vendor name) and then configure an output tool to use that field and output the data on the specific copy.
Thank you both for the answers. I will explore the topic a bit more.
I wonder, @nickmartella, if you could present to me the solution you have developed? I am curious about what is possible in this area when we combine Python and Alteryx.
from ayx import Alteryx
import shutil
import os
df = Alteryx.read("#1")
template_file = r"point to your docx template"
output_directory = r"folder location for files"
seen_vendors = set() # set to keep record of vendor names
for i, row in df.iterrows():
vendor_name = row["PO_VENDOR_NAME"] # reads this column in your alteryx data to create files
if vendor_name not in seen_vendors: # Check for duplicates
seen_vendors.add(vendor_name) # Add vendor name to the set if unique
new_file_name = f" (DESIRED FILE NAME).docx"
new_file_path = os.path.join(output_directory, new_file_name)
shutil.copy(template_file, new_file_path)
You can use this code in a python tool to create your files, then do your data work with the reporting tools. I would add a block until done, with this code as the first output and then the rest of the workflow on the 2nd output. Also in your new file name you can add the name of what makes it unique. Ours was vendor name, so it was 'file name - {vendor_name}.docx'
the best part about this method is you only have to make the template file once, then then you can do all the extra stuff in the workflow on your 2nd output from the block until done.