跳到主要内容

合并 Word 文档 Power Automate

此操作的作用

PDF4me合并文档 合并多个 Word 文件(DOCX/DOC)合并成您文档中的一个单一文档。 Power Automate 流量。控制流量。 合并顺序与排序位置选择样式处理方式(KeepSourceFormatting、UseDestinationStyles、KeepDifferentStyles),并设置 OOXML 合规级别。从以下位置提取文档 SharePointOneDrive无论是通过 Dropbox 还是电子邮件,输出结果都是一个干净的、单一的文件。 DOCX 可供分销或进一步加工。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

验证您的身份 API 要求

每一个 PDF4me 行动 Power Automate 需要有效 联系输入您的 PDF4me API 首次添加操作时,该操作会在所有后续操作中自动重用。 PDF4me 同一流程中的操作。

您不容错过的重要事实

SortPosition 控制合并顺序
数组中的每个文档都需要一个 SortPosition 值。文档按升序合并,位置 0 成为基准文档。您可以使用任何编号方案(0、1、2 或 10、20、30)。从循环中提取文件时,动态分配。 SortPosition 使用迭代索引,因此无论从存储中检索文件的方式如何,顺序始终是确定的。
FormatMode 决定如何协调风格
KeepSourceFormatting (默认)保留每个文档自身的样式。 UseDestinationStyles 将第一个文档的样式应用于所有合并的内容,最适合想要统一外观的情况。 KeepDifferentStyles 保留不同的样式,仅合并相同的样式。对于具有固定模板的品牌报告,请使用 UseDestinationStyles 以模板为位置 0。
DocContent 必须是二进制文件,而不是 URL 或路径
DocContent 每个文档的字段都期望接收 Word 文件的原始二进制内容,而不是…… SharePoint URL 或文件路径。使用 Power Automate 首先对每个文档执行“获取文件内容”操作,然后将其输出正文映射到 DocContent。 为了 SharePoint使用路径获取文件内容直接返回二进制文件,无需额外的编码步骤。
Power Automate PDF4me 的“合并文档”操作显示了包含两个条目的“文档”数组:每个条目都包含文件名、从 SharePoint 获取文件内容步骤映射的文档内容、排序位置 0 和 1 以及格式模式 UseDestinationStyles:此外,“合并选项合规级别”设置为“过渡”。

构建 Documents 数组,每个文件对应一个条目。映射 DocContent 来自“获取文件内容”步骤,而不是 URLSortPosition 0 为基础文档;其他文档按顺序附加。

参数

必需的: 文档数组,至少包含一个条目。每个条目需要文件名, DocContent (二进制文件),以及 SortPositionFormatMode 合并选项是可选的。

范围必需的它的作用例子
DocumentsYesArray of document objects to merge. Each object requires Filename, DocContent, and SortPosition. The array must contain at least one entry. Documents merge in ascending SortPosition order.[{Filename, DocContent, SortPosition}]
Documents[].FilenameYesFilename of the document including extension. Must be .docx or .doc. Used for format detection and document identification during merge.chapter1.docx
Documents[].DocContentYesRaw binary content of the Word file. Map from the output body of a SharePoint Get File Content or OneDrive Get File Content action. Do not pass a URL, path, or filename string here.File Content body
Documents[].SortPositionYesInteger determining merge order. The document with the lowest SortPosition becomes the base document. All others are appended in ascending order. Use any integers: 0, 1, 2 or 10, 20, 30 are both valid.0
Documents[].FormatModeNoHow styles are handled for this document during merge. Options: KeepSourceFormatting (default: preserves document's own styles), UseDestinationStyles (adopts base document styles), KeepDifferentStyles (retains distinct styles only).UseDestinationStyles
Merge Options Time ZoneNoTimezone identifier added to the merged document metadata. Use standard identifiers like UTC, Asia/Kolkata, or America/New_York. Default: none.UTC
Merge Options Compliance LevelNoOOXML compliance standard for the output document. Options: ECMA (ECMA-376 2006), Transitional (ISO 29500 Transitional, default and recommended), Strict (ISO 29500 Strict). Use Transitional for broadest Microsoft 365 compatibility.Transitional

输出字段

场地类型它包含什么
documentBinaryThe merged Word document as a binary. Map into SharePoint Create File, Send Email attachment, or a Convert Word to PDF action.
SuccessBooleantrue if the merge completed without errors. Use in a Condition step to branch on failure and send an error notification.
Error MessageStringHuman-readable error description if Success is false. Null when successful. Include in failure notification emails.
ErrorsArrayArray of detailed error objects when Success is false. Each entry has Code and Message fields for debugging.

常见错误信息

错误信息原因使固定
No documents to mergeDocuments array is null or emptyPass at least one document object in the Documents array with Filename, DocContent, and SortPosition.
Error loading document from bytesInvalid or corrupted Word file in DocContentVerify DocContent comes from a Get File Content action returning a valid .docx binary: not a URL or path.
Unknown FormatMode, defaulting to KeepSourceFormattingInvalid FormatMode valueUse only: KeepSourceFormatting, KeepDifferentStyles, or UseDestinationStyles.
Error merging documentsGeneral exception during mergeCheck that all documents are valid Word files (.docx). Review the Errors array for details.

快速设置

  1. 在你的 Power Automate 流程,点击 + 添加操作 并搜索 PDF4me 单词
  2. 选择 合并文档
  3. 请输入您的 PDF4me API 在连接对话框中输入(或选择现有连接)。
  4. 对于每个要合并的文档,添加一个 SharePoint 获取文件内容 或者 OneDrive 获取文件内容 执行此步骤之上的操作。
  5. 文件 数组,每个文件添加一个条目。设置 文件名 (和 .docx), DocContent (来自“获取文件内容”步骤的二进制文件),以及 SortPosition (0 代表基础文件,1、2……代表后续文件)。
  6. FormatMode: 使用 UseDestinationStyles 如果基础文档(位置 0)是您的品牌模板。
  7. 合并期权合规级别Transitional 为了获得最广泛的兼容性。
  8. 电线 文档 输出到 SharePoint 创建文件 或者 发送电子邮件 操作。添加一个 健康)状况成功 通过错误通知处理故障。

工作流程示例

工作流程示例Common Power Automate flow patterns using Merge Documents.
报告章节已批准 → 按顺序合并 → 通过电子邮件发送汇总报告
  1. A SharePoint 当报告的所有部分在状态列中都被标记为“已批准”时,项目更改将触发流程。
  2. 获取文件内容的四个步骤从报告库中检索封面(位置 0)、执行摘要(1)、正文(2)和附录(3)。
  3. 合并文档 将所有四种方式结合起来 SortPosition 订购 FormatMode 设置为 UseDestinationStyles封面模板的样式在整个页面中统一应用。
  4. 成功条件将失败情况路由到 Teams 通知,发送给报告所有者。
  5. 发送电子邮件时会将合并后的文件作为附件发送。 DOCX 向管理层邮件列表汇报。 SharePoint 创建文件会将其归档到已发布报告库中。
合同条款定稿 → 合并 → 转换为 PDF → 提交执行
  1. 审批触发器被触发 Power Automate 当合同审批流程中的法律审核步骤完成后。
  2. 获取文件内容步骤从法律库中检索合同标题(0)、条款和条件(1)、具体条款(2)和签名页(3)。
  3. 合并文档 汇编完整的合同。 FormatModeKeepSourceFormatting 合规级别为严格,符合法律文件标准。
  4. A PDF4me 将 Word 转换为 PDF 操作会生成合并合同的可打印 PDF 文件。
  5. 发送电子邮件会将编号的最终合同发送给交易对手。 SharePoint 档案馆 DOCXPDF 在“已执行合同”文件夹中。
提案章节数量不定 → 循环 → 收集 → 合并 → 发送给客户
  1. 当提案准备就绪时,手动触发器会启动。 SharePoint 获取文件功能检索所有文件 DOCX 该交易的“提案章节”文件夹中的章节。
  2. “Apply to Each”循环遍历文件列表。每次迭代都会运行“获取文件内容”函数,并将一个文档对象(文件名、二进制文件、迭代索引)附加到列表中。 SortPosition)到数组变量。
  3. 循环结束后, 合并文档 接收完整的数组。 FormatModeUseDestinationStyles文件夹中的第一个文件(位置 0)始终是品牌封面模板。
  4. 合并后的 DOCX 上传至客户交付物 SharePoint 库。发送电子邮件会将文件连同个性化的封面信息一起发送给客户联系人。

常见问题解答

What is SortPosition and how do I control the merge order?+
SortPosition is an integer assigned to each document in the Documents array. The action merges documents in ascending order: position 0 becomes the base document and all others are appended in order. You can use any integers: 0, 1, 2 or 10, 20, 30 are equally valid. When processing files from an Apply to Each loop in Power Automate, use the loop iteration index as SortPosition to ensure a deterministic merge order regardless of how SharePoint returns the files.
Which FormatMode should I use for branded company documents?+
Use UseDestinationStyles when the document at SortPosition 0 is your branded template: all merged content from other documents adopts the template's styles for a uniform look throughout the assembled document. Use KeepSourceFormatting (the default) when each document should retain its own styles, appropriate for merging independently authored sections where style variety is acceptable. Use KeepDifferentStyles when you want to preserve distinct styles from different contributors while merging identical style definitions.
Why does DocContent need to be the file binary and not a URL or SharePoint path?+
The DocContent field expects the raw binary bytes that make up the DOCX file. Use a SharePoint Get File Content or OneDrive Get File Content action before this step and map its Body (or File Content) output into DocContent. Passing a URL, a SharePoint path string, or a filename causes an invalid document error because the action cannot download or resolve file references: it can only process binary content it receives directly.
How do I merge a variable number of files: for example, all DOCX files in a SharePoint folder?+
Use an Apply to Each loop. Add a SharePoint Get Files action to list all DOCX files in the folder. Inside the loop, add Get File Content and append a document object (Filename, binary Content, and current item index as SortPosition) to an array variable initialized before the loop. After the loop exits, pass the completed array variable to the Merge Documents action. This pattern handles any number of files: from 2 to 200, without changing the flow structure.
What does the action return and how do I handle merge failures gracefully?+
The action returns document (merged DOCX binary), Success (boolean), Error Message (string), and Errors (array). After the action, add a Condition step that checks if Success equals true. On the false branch, use Send an Email or Post a Message (Teams) to notify the flow owner with the Error Message value so failures are visible without having to check run history manually. On the true branch, proceed with the Create File and email distribution steps.

相关操作

获取帮助