How to Process New Google Sheets or Excel Files in N8n Using Python Node?

I want to create an automation in N8n (in the cloud) that triggers whenever a new Google Sheets or Excel file is uploaded to Google Drive. The goal is to:

  1. Access the file in Python (e.g., read columns, make changes like dividing values, etc.).
  2. Save the modified file and re-upload it to Google Drive.

Locally, I would use a simple Python script like this:
import pandas as pd
df = pd.read_excel(‘file.xlsx’)
df[‘B’] = df[‘A’] / 2
df.to_excel(‘file.xlsx’, index=False)

How can I achieve a similar process in N8n? If Python isn’t possible, would a JavaScript node work instead?

Any help or examples would be appreciated!

1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
  • n8n version: 1.69.2
  • Database (default: SQLite): QLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own, main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): self-hosted in google cloud
  • Operating system: Windows10

Welcome to the community @Kiremit !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


That is not how you would do. You can set up Google Drive Trigger to act on new document. When data is received each row could be accessed/processed individually. No need to read the file as your data should be just plain JSON.

You could pull the whole file. Though you would rather convert its content to JSON with Extract from file node.

Read this doc to see how the JSON items (spreadsheet rows) would be handled by Python. Though, I would recommend utilising JavaScript instead if you are familiar with it. Moreover, you might not even need Code node for that depending on what you want to do with the data in the spreadsheet.

1 Like

The question is how do I access that file or the converted data in the python module then and how would I export it to the same/ or a new file again.
Screenshot 2024-12-05 115226

To convert processed data to file use the node Convert to File.

Here’s a rough example if you are still struggling to understand.

Having said that you might rather want already created files updated. Then there is no need to convert the data to file. Just update the data in those files without downloading them (only pulling the data first to have them updated in n8n).

1 Like

Hi,

thanks for the illustration. I get your core idea but the main problem is how to access the file/data in the actual code. The input and output within python is the core problem

I’m not following your problem. When you pull the data from Google Sheet of Excel file you have plain data in JSON format with each item representing a row (similarly to the data output you see in “Data from Sheet” node in my example workflow). The Code node already showed you how to work with that data.

If you’re trying to process new Google Sheets or Excel files in N8n using a Python node, it’s pretty straightforward once you break it down. First, ensure your N8n workflow is set to trigger when a new file is uploaded—like using the Google Drive trigger for Sheets or a file trigger for Excel. Once that’s set, you can use the Python node to read and process the data. Then, pass the results to the next N8n node. It could be an email node to send a report or a database node to update records. Here’s a handy guide on excel formulas examples in case you need inspiration! It’s fun to tinker around and saves a ton of manual effort once it’s running.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.