Excel 或 Google Sheets 与 Postgres 双向同步
这是一个Miscellaneous, Multimodal AI领域的自动化工作流,包含 8 个节点。主要使用 Code, Postgres, ManualTrigger, MicrosoftExcel, ScheduleTrigger 等节点。 Excel 或 Google Sheets 与 Postgres 双向同步
- •PostgreSQL 数据库连接信息
{
"meta": {
"instanceId": "04c7c3f1743831184e4a6edaf1f906dbab0c745cc98b8af3ef7660bbefe74cb4"
},
"nodes": [
{
"id": "e6bc660d-99b9-4321-ad7b-73f4b73a80f9",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-656,
-320
],
"parameters": {
"color": 6,
"width": 976,
"height": 752,
"content": "## 同步 Excel 表格与 Postgres 数据库"
},
"typeVersion": 1
},
{
"id": "9a97bb0b-9428-424f-952c-0d83dca0e94f",
"name": "清理日期",
"type": "n8n-nodes-base.code",
"position": [
-96,
16
],
"parameters": {
"jsCode": "return items.map(item => {\n const inputDate = item.json[\"date\"];\n let formattedDate = null;\n let dateObj;\n\n // Handle Excel serial number\n if (typeof inputDate === \"number\") {\n const baseDate = new Date(Date.UTC(1899, 11, 30));\n baseDate.setDate(baseDate.getDate() + inputDate);\n dateObj = baseDate;\n }\n\n // Handle string format\n else if (typeof inputDate === \"string\") {\n const parsed = new Date(inputDate);\n if (!isNaN(parsed)) {\n dateObj = parsed;\n }\n }\n\n // Format date as MM/DD/YYYY\n if (dateObj) {\n const M = String(dateObj.getMonth() + 1).padStart(2, '0');\n const D = String(dateObj.getDate()).padStart(2, '0');\n const Y = dateObj.getFullYear();\n formattedDate = `${M}/${D}/${Y}`;\n }\n\n item.json[\"date\"] = formattedDate;\n return { json: item.json };\n});\n"
},
"typeVersion": 2
},
{
"id": "71ef2eee-cb60-48ad-9050-df5a27f1a568",
"name": "点击同步 Excel -> 数据库",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-576,
-176
],
"parameters": {},
"typeVersion": 1
},
{
"id": "a3a85552-617f-4aa2-b29f-2d7196c7148c",
"name": "执行同步 Excel -> 数据库",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-576,
16
],
"parameters": {
"inputSource": "passthrough"
},
"typeVersion": 1.1
},
{
"id": "a17a319e-ef1e-4a2a-b5f4-302628b811c5",
"name": "计划同步 Excel -> 数据库",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-576,
208
],
"parameters": {
"rule": {
"interval": [
{}
]
}
},
"typeVersion": 1.2
},
{
"id": "705234f6-2f3b-45fd-a072-09da5ea65ce1",
"name": "获取表",
"type": "n8n-nodes-base.microsoftExcel",
"position": [
-256,
16
],
"parameters": {
"limit": 200,
"table": {
"__rl": true,
"mode": "list",
"value": "",
"cachedResultUrl": "",
"cachedResultName": "Clients"
},
"filters": {},
"resource": "table",
"workbook": {
"__rl": true,
"mode": "list",
"value": "",
"cachedResultUrl": "",
"cachedResultName": ""
},
"operation": "getRows",
"worksheet": {
"__rl": true,
"mode": "list",
"value": "",
"cachedResultUrl": "",
"cachedResultName": "CLIENTS"
}
},
"credentials": {
"microsoftExcelOAuth2Api": {
"id": "",
"name": ""
}
},
"typeVersion": 2.1
},
{
"id": "b674a99d-e5a1-45d4-9092-e9b66a7943f8",
"name": "更新或插入表",
"type": "n8n-nodes-base.postgres",
"position": [
80,
16
],
"parameters": {
"table": {
"__rl": true,
"mode": "list",
"value": "clients",
"cachedResultName": "clients"
},
"schema": {
"__rl": true,
"mode": "list",
"value": "public",
"cachedResultName": "public"
},
"columns": {
"value": {
"no": 0
},
"schema": [
{
"id": "no",
"type": "number",
"display": true,
"removed": false,
"required": true,
"displayName": "no",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "autoMapInputData",
"matchingColumns": [
"no"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "upsert"
},
"credentials": {
"postgres": {
"id": "",
"name": ""
}
},
"typeVersion": 2.6
},
{
"id": "30ed085e-d0ba-4271-a92e-61dece670542",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1264,
-320
],
"parameters": {
"width": 592,
"height": 752,
"content": "## Excel ↔ 数据库同步"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Get Table": {
"main": [
[
{
"node": "Sanitize Date",
"type": "main",
"index": 0
}
]
]
},
"Sanitize Date": {
"main": [
[
{
"node": "Upsert Table",
"type": "main",
"index": 0
}
]
]
},
"Exec Sync Excel -> DB": {
"main": [
[
{
"node": "Get Table",
"type": "main",
"index": 0
}
]
]
},
"Click Sync Excel -> DB": {
"main": [
[
{
"node": "Get Table",
"type": "main",
"index": 0
}
]
]
},
"Schedule Sync Excel -> DB": {
"main": [
[
{
"node": "Get Table",
"type": "main",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 杂项, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
AureusR
@aureusrExperienced Operations and Workflow Manager with a Master’s degree in Electronics and Software Development. I specialize in designing and implementing efficient, automated systems that help teams save time, reduce errors, and scale with confidence. My expertise spans across business process optimization, automation platforms, and custom workflow solutions. Looking to streamline your operations? Book a consultation with me to explore tailored automation strategies and n8n-powered workflows.
分享此工作流