Data-Driven Report Generation with Gemini AI and Google Docs - n8n Workflow

Use this advanced n8n workflow to automatically transform uploaded Excel or CSV data into structured, professional reports analyzed by Gemini AI and formatted in Google Docs. Explore complex n8n templates.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Consultants & Analysts: Who need to quickly generate detailed reports from raw data sets.

  • Public Sector Professionals: Specifically designed to analyze data for public services (water, waste, etc.), as indicated by the AI system prompts.

  • Developers utilizing n8n: Looking for complex examples of chaining multiple specialized n8n node components, including custom code and AI agents.

  • Users needing high-volume reporting automation: Automating document creation using n8n templates and large language models.

Overview

Generating comprehensive professional reports from raw spreadsheet data can be time-consuming, requiring extensive data preparation, analysis, and formatting. This powerful n8n workflow provides an end-to-end solution, drastically cutting down generation time.

The automation uses a secure webhook to receive the data file (Excel or CSV), extracts all content, and aggregates it into a single input payload. It then leverages the Gemini AI model in a two-stage n8n agent system:


  1. Analysis Stage: The first AI Agent analyzes the data and produces a structured JSON summary of key findings.

  2. Generation Stage: The second AI Agent takes the JSON summary and uses Google Docs tools (integrated as AI Agent Tool calls) to generate a fully formatted, high-quality document, including titles, sections, and properly styled tables. This advanced n8n workflow demonstrates how to integrate external services for sophisticated, professional document output.

How it Works

This n8n workflow operates via a defined sequence of steps:


  1. Trigger (Webhook): The process is initiated when an external system sends a file upload via a POST request to the Webhook n8n trigger.

  2. Data Extraction: The Extract from File n8n node processes the binary data, converting the spreadsheet rows into usable JSON items.

  3. Data Aggregation: The subsequent Aggregate and Aggregate Data (Code n8n node) steps consolidate all individual data rows into one single JSON string. This optimized payload is passed to the LLM.

  4. First AI Analysis (AI Agent): The first AI Agent n8n node (powered by Google Gemini) receives the raw data string. Its mission is defined to analyze the data against the context of public services and output a clean, structured JSON analysis.

  5. Output Cleaning: The Parse and Clean AI Response Code n8n node is critical. It robustly strips away markdown fencing (```json) and any surrounding explanatory text added by the AI, ensuring only valid JSON proceeds.

  6. Second AI Generation (AI Agent1): The second AI Agent receives the clean JSON analysis. This n8n node is configured to use Google Docs tools to generate and format the final report. It instructs the LLM to structure the content, apply heading styles, insert tables, and ensure professional formatting.

  7. Final Output: The second agent uses the AI Agent Tool (a proxy for Google Docs actions) to complete the document generation. The final output from this n8n node is the downloadable .docx link, which is then sent back to the caller via the Respond to Webhook n8n node.

Installation Guide

To set up this n8n workflow template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it directly into your n8n instance via the 'New' menu -> 'Import from JSON'.

  2. Set Up Credentials: This n8n workflow requires credentials for Google services and Gemini AI.

Google Gemini (PaLM) API: Set up credentials for the Google Gemini Chat Model and Embeddings Google Gemini n8n nodes. Ensure your API key has access to the specified models (models/gemini-2.5-pro).
Google Docs OAuth2 API: Set up OAuth2 credentials for the Google Docs tools used by the second AI Agent.
* Google Slides/Gmail (Optional Tools): Set up OAuth2 credentials for Google Slides and Gmail Tool if the AI Agent decides to use them, although the primary path uses Google Docs.

  1. Activate the Webhook: After saving the n8n workflow, click the Webhook n8n trigger node to retrieve the unique URL. This URL is where you will send your data files (POST request).

  2. Test: Execute the n8n workflow manually or send a sample XLSX/CSV file to the webhook URL to ensure proper data extraction and AI analysis.

Node Details

Webhook (n8n trigger): The entry point of this n8n workflow, listening for POST requests to the path /generer-rapport containing binary file data.
Extract from File (n8n node): Essential for handling structured file uploads (Excel/CSV). Converts the binary spreadsheet content into a stream of JSON objects (data rows).
Aggregate Data (Code n8n node): A custom JavaScript n8n node that converts the data stream from the spreadsheet into a single, large JSON string optimized for LLM input.
AI Agent & Google Gemini Chat Model (n8n node): The first stage of analysis. This n8n node performs an intelligent, data-driven analysis of the spreadsheet content based on predefined system instructions (specialized for public service reports).
Parse and Clean AI Response (Code n8n node): A crucial technical step. This n8n node uses custom code to ensure the AI output is a pristine JSON object by stripping surrounding text and markdown syntax.
AI Agent1 & Google Gemini Chat Model2 (n8n node): The second, more complex agent. This n8n node focuses on transformation. It uses its language model and integrated Google Workspace tools to generate the final, formatted Google Docs report.


  • AI Agent Tool1 (n8n node): Serves as the gateway for the AI to interact with Google Docs, Google Slides, and Gmail n8n nodes, allowing the agent to dynamically create and format the output document based on the analysis.

Related n8n Workflows

Free

Nodes: 21 Nodes
Updated: December 26 2025
View all
Created by

Featured*