{
  "name": "Image to Excel (.xlsx) & Google Sheets OCR Workflow",
  "nodes": [
    {
      "parameters": {
        "content": "## Image to Excel (.xlsx) & Google Sheets OCR\nUpload a JPG, PNG, or WebP photo of a table. StructOCR extracts clean headers and rows via POST /v1/image-to-excel, expands them into spreadsheet rows, and outputs both an Excel (.xlsx) file and Google Sheets rows.\n\n**Setup**\n1. Get a free API key (200 credits = 100 images) at https://structocr.com/register\n2. In the StructOCR HTTP Request node, create a Header Auth credential: Name `x-api-key`, Value = your key.\n3. Optionally connect your spreadsheet in the Google Sheets node (or keep only the Convert to XLSX node).\n4. Open the Form Trigger URL and upload any table photo.\n\nFull Guide: https://structocr.com/blog/platforms/n8n-image-to-excel-ocr",
        "height": 400,
        "width": 460
      },
      "id": "note-1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -140
      ]
    },
    {
      "parameters": {
        "formTitle": "Upload a Table Photo or Screenshot",
        "formDescription": "Upload a JPG, PNG, or WebP image (up to 10 MB) to convert into Excel (.xlsx) and Google Sheets rows.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "image",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".jpg,.jpeg,.png,.webp,.pdf",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "id": "trigger-1",
      "name": "Upload Table Image",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "4f8c1d7e-3b2a-49c1-9a11-7e5b6c8d2094"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.structocr.com/v1/image-to-excel",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "image"
            },
            {
              "parameterType": "formData",
              "name": "mode",
              "value": "tables"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "http-1",
      "name": "StructOCR Image to Excel",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "StructOCR API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// n8n Code node — Run Once for All Items\n// Expands document.tables[] into one item per spreadsheet row\nconst output = [];\n\nfor (const item of $input.all()) {\n  const res = item.json;\n  if (!res.success) {\n    output.push({ json: { _ok: false, _error: res.error ?? 'OCR_FAILED', _message: res.message ?? '' } });\n    continue;\n  }\n  const tables = res.document?.tables ?? [];\n  for (const table of tables) {\n    const headers = table.headers ?? [];\n    for (const row of table.rows ?? []) {\n      const record = { _table: table.title || table.id || 'Table 1' };\n      headers.forEach((h, idx) => {\n        const key = String(h || `col_${idx + 1}`).trim();\n        record[key] = row[idx] ?? '';\n      });\n      output.push({ json: record });\n    }\n  }\n}\n\nreturn output;"
      },
      "id": "code-1",
      "name": "Expand Table Rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "operation": "xlsx",
        "binaryPropertyName": "data",
        "options": {
          "fileName": "extracted-table.xlsx",
          "headerRow": true,
          "sheetName": "Extracted Data"
        }
      },
      "id": "xlsx-1",
      "name": "Convert to Excel (.xlsx)",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        740,
        -100
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "sheets-1",
      "name": "Append to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        740,
        100
      ]
    }
  ],
  "connections": {
    "Upload Table Image": {
      "main": [
        [
          {
            "node": "StructOCR Image to Excel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "StructOCR Image to Excel": {
      "main": [
        [
          {
            "node": "Expand Table Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Expand Table Rows": {
      "main": [
        [
          {
            "node": "Convert to Excel (.xlsx)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Append to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
