Hi everyone,
Im currently developing a workflow to crawl data from any excel(.xls, .xlsx) and word(.docx) files from an email received. I have already done getting binary files from an email received. How can i set up my agent ai to access these binary files and extract the data in specific format. Here is what i have done so far.
Please tell me if you need any more informations. Thank you !
Can you tell us why did you use email trigger instead of gmail trigger? do you use another email platform other than gmail? Since gmail trigger lets you get the files and from that they will get treated.
actually my company’email is using IMAP so i need to use email trigger node to listen for emails. It’s another email platform other than gmail.
Of course, here is the JSON code and a detailed message with instructions for you in English.
Message For You
Hello,
You’ve done an excellent job setting up the initial part of your n8n workflow to receive emails and correctly identify Excel and Word attachments. The next critical step is to read the content from these files and pass it to an AI agent to extract the data into your desired format.
Your existing “Switch1” node will now branch into two separate paths: one for Excel files and one for Word files. By following the instructions and using the JSON code below, you can easily complete your workflow.
Next Steps:
-
Read Excel Files: From the “excel” output of your Switch1 node, add a new node that will read the binary data and convert it into a structured JSON format. We will use the Read From File or Spreadsheet File node for this.
-
Read Word Files: From the “word” output of your Switch1 node, add a Code node. This node will run a script to extract the plain text content from the Word file’s binary data.
-
Send Data to AI Agent: The data from both paths (JSON from Excel, text from Word) will then be sent to an AI Agent node. This agent will use a prompt you provide to understand the data and output it in a clean, structured JSON format.
Simply copy the JSON code provided below and paste it onto your n8n canvas. It will create the necessary nodes for you.
How to Use the JSON Code
-
Copy: Copy the entire JSON code block above.
-
Paste: Go to your n8n workflow editor, right-click on an empty part of the canvas, and select “Paste” (or press Ctrl+V / Cmd+V).
-
Connect the Nodes:
-
Connect the excel output from your existing Switch1 node to the input of the new Read Excel File node.
-
Connect the word output from your Switch1 node to the input of the new Extract Text from Word node.
-
(The connections should be created automatically by the JSON, but it’s good to double-check).
-
Configure the New Nodes:
-
For Extract Text from Word: You may need to allow n8n to use external npm packages. You can do this by setting the environment variable NODE_FUNCTION_ALLOW_EXTERNAL=mammoth.
-
For AI Agent for Excel and AI Agent for Word: Select each node, set up your credentials for the AI model you are using (e.g., OpenAI, Gemini), and adjust the prompt if needed to better fit your specific data
1 Like
Thankyou for your answer but can you tell me more how to setup the Extract Text from Excel and the AI Agent nodes because when i paste in my workflow, it shows like this: (my n8n version is 1.112.5)