关于 syncfusion-angular-docx-editor
为开发者生成将 Syncfusion DOCX Editor 集成到 Angular 应用的代码与示例,内容按编辑器功能分类。它要求先确认代码交付方式,并依据参考文件生成代码。
主要功能
- 01Angular 编辑器集成代码
- 02文档编辑与格式设置
- 03修订和评论操作
- 04文档保护与表单字段
- 05查找和替换代码示例
- 06工具栏与 Ribbon 定制
适用场景
- 01在 Angular 页面嵌入文档编辑器
- 02配置只读或修订保护
- 03为文档添加评论或表单字段
- 04实现查找替换功能
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ syncfusion/ docx-editor-sdk-skills --skill syncfusion-angular-docx-editor安装后在 Claude Code 中输入/syncfusion-angular-docx-editor确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.mdreferences/collaborative-editing-core.mdcollaborative-editing-java.mdcomments.mdcustomize-ribbon.mdcustomize-tool-bar.mddocument-protection.mdeditor-only.mdfind-and-replace.mdform-fields.mdgetting-started.mdinsert-text-box.mdpaste-formatting.mdribbon.mdspell-check.mdtrack-changes.md详细介绍
Syncfusion Angular DOCX 编辑器
概述
此技能可帮助开发者生成 Angular 代码,以便在应用中集成 Syncfusion DOCX 编辑器。它提供可直接使用的代码片段和最佳实践,用于嵌入支持编辑、审阅、格式设置等功能的文档编辑器。
主要功能
- 文档编辑: 创建、编辑和查看 Word 文档。
- 保护: 设置只读模式、允许添加评论、允许填写表单、强制启用修订,并定义可编辑区域。
- 审阅: 启用修订(更改记录),并接受或拒绝更改。
- 评论: 添加评论、回复和作者元数据。
- 查找和替换: 以编程方式执行查找和替换操作,实现自动化。
- 表单字段: 插入并填写文本字段、复选框和下拉表单字段。
先决条件
- npm 包:
@syncfusion/ej2-angular-documenteditor - Syncfusion 许可证:https://www.syncfusion.com/products/communitylicense
快速入门示例
示例 1:创建文档编辑器
用户:“给我展示创建文档编辑器组件的代码。”
**结果:**用于初始化文档编辑器组件的 Angular 代码片段
示例 2:启用只读限制模式
用户:“创建一个启用了只读限制模式的文档编辑器。”
**结果:**用于创建启用了只读保护的文档编辑器的 Angular 代码片段
开始使用 — 最简 Angular 代码
适用于普通 Web 项目的最简 Angular 文档编辑器配置:
import { DocumentEditorContainerModule } from '@syncfusion/ej2-angular-documenteditor';
import { Component, OnInit } from '@angular/core';
import { ToolbarService } from '@syncfusion/ej2-angular-documenteditor';
@Component({
imports: [
DocumentEditorContainerModule
],
standalone: true,
selector: 'app-root',
template: `<ejs-documenteditorcontainer
serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
height="600px"
style="display:block"
[enableToolbar]=true>
</ejs-documenteditorcontainer>`,
providers: [ToolbarService]
})
export class AppComponent implements OnInit {
ngOnInit(): void {
}
}
注意:示例中的
serviceUrl用于评估/演示。生产环境中请托管自己的服务。
CSS(styles.css):
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-documenteditor/styles/material.css';
为用户的项目生成 Angular 代码
触发关键词:“代码”、“代码片段”、“如何操作”、“给我展示”、“示例”、“示例代码”、“生成代码”、“实现”、“添加到组件”、“配置 documenteditor”、“创建”、“angular document editor”、“docx editor”、“document editor”、“track changes”、“load docx”、“comments”、“accept changes”、“protect document”、“find and replace”、“content control”
工作流:
-
分析用户的请求,确定所需功能(例如,修订、限制编辑、自定义工具栏)。
-
阅读相关的
references/*.md文件,了解所需功能对应的 API 和代码模式。 -
**生成代码前先暂停。**检查用户是否已选择交付方式。
-
如果用户尚未选择交付方式,必须先使用以下简洁的单选问题询问用户:
“你希望如何接收生成的代码?”
- **选项 1:**替换特定项目文件中的代码(需要提供文件路径并确认)
- **选项 2:**直接在聊天窗口中分享代码
-
**只有在用户选择交付方式后,**才能使用
references/*.md中的 API 和代码片段生成 Angular 代码,并将具体占位内容替换为用户项目中的实际内容。 -
除非用户明确选择选项 1、提供文件路径并授予权限,否则不得更改工作区项目文件。
-
提供代码后,给出完整的 Angular 代码片段和简洁的集成步骤。
请参阅 ## Rules 部分,了解操作约束(输出目录、临时文件、允许使用的库等)。
代码参考
所有代码片段和示例都位于 references/ 文件夹中。每个文件都包含:
- 最简 Angular 代码 — 可运行、可直接使用的代码片段
- 占位符 — 用户必须自定义的值
- 说明 — 最佳实践、其他需要注意的信息和使用限制
| 文件 | 内容 |
|---|---|
| getting-started.md | Document Editor 初始化和容器设置 |
| editor-only.md | 通过手动注入模块实现仅编辑器模式 |
| form-fields.md | 插入、检查、填写、重置和导出表单字段 |
| comments.md | 添加、回复、浏览和删除批注 |
| track-changes.md | 启用修订并接受或拒绝更改 |
| document-protection.md | 只读、仅批注、表单和修订保护 |
| spell-check.md | 拼写检查设置、建议和自定义词典 |
| customize-toolbar.md | 自定义工具栏项、按钮状态和窗格控制 |
| find-and-replace.md | 搜索、替换和搜索结果管理 |
| paste-formatting.md | 通过后端服务保留剪贴板格式 |
| insert-text-box.md | 插入文本框对话框 |
| ribbon.md | 使用 Ribbon UI 初始化 documenteditor |
| customize-ribbon.md | 自定义 Ribbon 选项卡 |
| collaborative-editing-core.md | 使用 Collaboration Client 和 Server 协同编辑(ASP.NET Core 后端) |
| collaborative-editing-java.md | 在 Java(Spring Boot)后端中使用 SockJS、STOMP 和 Redis 协同编辑 |
代码生成关键规则
-
SKILL.md 中不得包含内联代码 — 始终指向
references/*.md中的代码片段。每次提示都会加载此文件;内联代码会浪费令牌。 -
代码片段必须经过测试 — 所有代码都必须能够使用当前版本的
@syncfusion/ej2-angular-documenteditornpm 包编译并运行。 -
最简代码 + 占位符 + 说明 — 每个参考文件都必须包含:
- 最简代码(完整、可运行的代码片段)
- 占位符(用户必须替换的值,使用
{{ }}或[PLACEHOLDER]标记) - 说明(最佳实践、特定于框架的调整、限制)
-
针对需求提供代码和说明 — 切勿创建临时文件或脚本。
-
许可证处理 — 切勿将许可证密钥硬编码。请引导用户使用环境变量或配置文件。
-
不得虚构 API — 只能使用已验证的 Syncfusion DOCX Editor SDK 方法名称。一个错误的方法就会损害用户的信任。
-
服务 URL 说明 — 当 serviceUrl 包含 https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/ 时,请在代码片段中保留该 URL,并添加说明:“Document Editor 中的 serviceUrl 属性仅用于演示和评估。用于生产环境时,请自行托管 Web 服务。”
规则
- 只能使用 Syncfusion Document Editor API — 切勿推荐或使用其他 Word Editor 库。
- 不得创建临时文件 — 切勿在输出目录之外创建临时脚本、中间文件或脚手架
- 仅限 Angular 代码 — 所有生成的代码都必须是有效的 Angular 代码,切勿生成原生 JavaScript、jQuery 或非 Angular 编码模式