syncfusion-dotnet-excel
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExcel (XLSX / XLS) Document Processing
Excel(XLSX / XLS)文档处理
Overview
概述
Create, edit, and convert Excel (.xlsx, .xls) files using the Syncfusion Excel Library.
This skill supports two operational modes — generating C# code for the user's project or executing tasks directly through a CSX script.
使用Syncfusion Excel库创建、编辑和转换Excel(.xlsx、.xls)文件。
此技能支持两种操作模式——为用户项目生成C#代码,或直接通过CSX脚本执行任务。
Key Capabilities
核心功能
- Create & Edit: Workbooks, worksheets, cells, rows, columns, cell formatting, styles, formulas, names ranges, charts, shapes, images, hyperlinks, comments, data validation, conditional formatting
- Advanced Features: Template markers and mail merge, data binding (DataTable, collections, objects), pivot tables, pivot charts, slicers, auto-fill, fill series, what-if analysis scenarios, custom XML, drawing objects (text boxes, checkboxes, shapes), VBA macros
- Data Management: Import data (CSV, DataTable, collections, nested objects, XML, HTML tables), export data (ranges, tables, named ranges), find/replace with regex, advanced filtering (top10, custom, color, icon filters), freeze panes, show/hide rows/columns/sheets
- Conversion: Excel to PDF, Excel to JSON, Excel to CSV (import/export)
- Security: Password encryption/decryption, document protection, permission settings
- Page Setup: Margins, headers/footers, print areas
- 创建与编辑:工作簿、工作表、单元格、行、列、单元格格式、样式、公式、命名区域、图表、形状、图片、超链接、批注、数据验证、条件格式
- 高级功能:模板标记与邮件合并、数据绑定(DataTable、集合、对象)、数据透视表、数据透视图、切片器、自动填充、序列填充、假设分析场景、自定义XML、绘图对象(文本框、复选框、形状)、VBA宏
- 数据管理:导入数据(CSV、DataTable、集合、嵌套对象、XML、HTML表格)、导出数据(区域、表格、命名区域)、正则表达式查找/替换、高级筛选(前10项、自定义、颜色、图标筛选)、冻结窗格、显示/隐藏行/列/工作表
- 格式转换:Excel转PDF、Excel转JSON、Excel转CSV(导入/导出)
- 安全防护:密码加密/解密、文档保护、权限设置
- 页面设置:边距、页眉/页脚、打印区域
Prerequisites
前提条件
- .NET SDK 8+ and :
dotnet-scriptdotnet tool install -g dotnet-script - Syncfusion License: https://www.syncfusion.com/products/communitylicense
- .NET SDK 8+ 和 :
dotnet-scriptdotnet tool install -g dotnet-script - Syncfusion 许可证:https://www.syncfusion.com/products/communitylicense
Quick Start Examples
快速入门示例
Example 1: Generate Code (Mode 1)
示例1:生成代码(模式1)
User: "Show me how to create an Excel workbook with a table"
Result: C# code snippet displayed (no files created)
用户: "展示如何创建带表格的Excel工作簿"
结果: 显示C#代码片段(不创建文件)
Example 2: Execute Task (Mode 2)
示例2:执行任务(模式2)
User: "Create an Excel spreadsheet with sales data at output/report.xlsx"
Result: Physical file created at specified path
用户: "在output/report.xlsx路径创建包含销售数据的Excel电子表格"
结果: 在指定路径创建实体文件
Two Modes — Choose Based on User Intent
两种模式——根据用户意图选择
Before choosing a mode, infer what the user wants to accomplish:
选择模式前,先推断用户的目标:
Mode 1: Generate C# Code for the User's Project (default)
模式1:为用户项目生成C#代码(默认)
Use this mode when the user wants to view, write, review, refactor, or modify C# code related to Excel processing.
Trigger keywords: "code", "snippet", "how to write", "Program.cs", "show me", "sample", "example code", "generate code for", "NuGet", "add to project", "integrate", "implementation", "usage example", "API example", "learn", "teach", "how do I", "I want to", "I need to", "help me implement", "library", "package", "ASP.NET", "Blazor", "WPF", "WinForms", "MAUI", "console app", "sort", "sorting", "sorted", "chart to image", "export chart", "chart as image", "hyperlink", "link", "links", "find replace", "replace", "filter", "filtering", "pivot", "template", "marker", "formula", "function".
Workflow:
当用户需要查看、编写、评审、重构或修改与Excel处理相关的C#代码时,使用此模式。
触发关键词: "code"、"snippet"、"how to write"、"Program.cs"、"show me"、"sample"、"example code"、"generate code for"、"NuGet"、"add to project"、"integrate"、"implementation"、"usage example"、"API example"、"learn"、"teach"、"how do I"、"I want to"、"I need to"、"help me implement"、"library"、"package"、"ASP.NET"、"Blazor"、"WPF"、"WinForms"、"MAUI"、"console app"、"sort"、"sorting"、"sorted"、"chart to image"、"export chart"、"chart as image"、"hyperlink"、"link"、"links"、"find replace"、"replace"、"filter"、"filtering"、"pivot"、"template"、"marker"、"formula"、"function"。
工作流:
Step 1 — Detect the Application Type and Suggest the Correct NuGet Package(s)
步骤1 — 检测应用类型并推荐正确的NuGet包
-
Inspect the workspace project files (,
.csproj,web.config,App.config,Startup.cs, etc.) and use the detection signals table inProgram.csto identify the application type.references/nuget-packages.md -
Look up the correct package(s) frombased on the detected app type and tell the user to install them before generating any code.
references/nuget-packages.md
-
检查工作区项目文件(、
.csproj、web.config、App.config、Startup.cs等),使用Program.cs中的检测信号表识别应用类型。references/nuget-packages.md -
根据检测到的应用类型,从中查找正确的包,并告知用户在生成任何代码前先安装它们。
references/nuget-packages.md
Step 2 — Generate Code from Reference Files Only
步骤2 — 仅从参考文件生成代码
Do NOT invent, guess, or suggest any API, method, property, class, or namespace not explicitly present in the reference files.
- Read the relevant file(s) for the requested feature
references/*.md - Build C# code strictly from the APIs and snippets found in those files
- Select the correct snippet variant based on the app type detected in Step 1:
- Windows-specific apps (WinForms, WPF, .NET Framework Console, ASP.NET MVC4/5, UWP) → use Windows-specific snippets
- Cross-platform apps (ASP.NET Core, .NET Core/.NET 5+ Console, Blazor, MAUI, Xamarin) → use cross-platform / snippets
.Net.Core
- Do not create or run any script
.csx
不得发明、猜测或使用参考文件中未明确提及的任何API、方法、属性、类或命名空间。
- 读取与请求功能相关的文件
references/*.md - 严格基于这些文件中的API和片段构建C#代码
- 根据步骤1中检测到的应用类型选择正确的代码片段变体:
- Windows专属应用(WinForms、WPF、.NET Framework控制台、ASP.NET MVC4/5、UWP)→ 使用Windows专属片段
- 跨平台应用(ASP.NET Core、.NET Core/.NET 5+控制台、Blazor、MAUI、Xamarin)→ 使用跨平台/片段
.Net.Core
- 不得创建或运行任何脚本
.csx
Mode 2: Execute via CSX Script (does not touch project files)
模式2:通过CSX脚本执行(不修改项目文件)
Use this mode only when the user explicitly requests execution, file generation, or a fully produced output (such as a completed XLSX file).
Trigger keywords: "create a workbook", "create an Excel file", "generate a spreadsheet", "make a spreadsheet", "generate a file", "open", "edit", "modify", "change" an file, "without modifying my project", "run a csx script", "just create it", "build me", "export to excel", "save as", "output", "result", "export", "convert", "transform", "file path", or when the user provides a file path (e.g., , , ).
.xlsxoutput/report.xlsx~/Documents/sales.xlsx/tmp/data.xlsxWorkflow:
仅当用户明确要求执行、生成文件或生成完整输出(如已完成的XLSX文件)时,使用此模式。
触发关键词: "create a workbook"、"create an Excel file"、"generate a spreadsheet"、"make a spreadsheet"、"generate a file"、"open"、"edit"、"modify"、"change" an file、"without modifying my project"、"run a csx script"、"just create it"、"build me"、"export to excel"、"save as"、"output"、"result"、"export"、"convert"、"transform"、"file path",或当用户提供文件路径时(如 、、)。
.xlsxoutput/report.xlsx~/Documents/sales.xlsx/tmp/data.xlsx工作流:
Step 1 — Create Temp CSX Script
步骤1 — 创建临时CSX脚本
- Start with as the base
references/template.csx - Create at: (e.g.,
{skill-root}/syncfusion-dotnet-excel/scripts/temp-{timestamp}.csx=skill-root).codestudio/skills - Use Unix timestamp for unique filename; never create in workspace root
- 以为基础
references/template.csx - 创建路径:(例如
{skill-root}/syncfusion-dotnet-excel/scripts/temp-{timestamp}.csx=skill-root).codestudio/skills - 使用Unix时间戳确保文件名唯一;绝不能在工作区根目录创建
Step 2 — Build Script from Reference Files
步骤2 — 基于参考文件构建脚本
- Do NOT invent APIs/methods not in reference files
- Read relevant file(s) and extract code snippets
references/*.md - Replace all placeholders: file paths, sheet names, cell values, data, field names, etc.
- 不得使用参考文件中未包含的API/方法
- 读取相关的文件并提取代码片段
references/*.md - 替换所有占位符:文件路径、工作表名称、单元格值、数据、字段名等
Step 3 — Execute Script
步骤3 — 执行脚本
- Run:
dotnet script {skill-root}/syncfusion-dotnet-excel/scripts/temp-{timestamp}.csx - Verify successful execution and capture any errors
- 运行:
dotnet script {skill-root}/syncfusion-dotnet-excel/scripts/temp-{timestamp}.csx - 验证执行是否成功并捕获所有错误
Step 4 — Clean Up and Report
步骤4 — 清理并报告
- Delete the temp file after execution
.csx - Report SUCCESS/ERROR with output file path(s) and any error messages with fixes
- 执行完成后删除临时文件
.csx - 报告执行成功/失败,并提供输出文件路径及错误信息与修复建议
Code References
代码参考
All templates and snippets are in the folder:
references/| File | Contents |
|---|---|
| nuget-packages.md | NuGet package mappings by application type (Mode 1) |
| template.csx | Base CSX script structure and license registration |
| document-structure.md | Create/save/close workbook, add/rename/delete/move sheets |
| template-markers.md | Template marker binding: variables, DataTable, lists, DataSet |
| cell-formatting.md | Cell formatting, number formats, styles, autofit |
| cell-values.md | Cell values and operations: set/read text, numbers, formulas, dates, booleans, detect type |
| cell-access-manipulation.md | Access cells relatively, discontinuous ranges, migrant range, precedent/dependent cells, clear content |
| formulas-advanced.md | Cross-sheet references, array formulas, external references, named ranges, calculated columns, calculation modes, formula auditing |
| charts.md | Create and configure charts |
| excel-csv.md | Import/export CSV |
| excel-to-json.md | Convert worksheets or ranges to JSON |
| excel-to-pdf.md | Convert workbook to PDF using renderer |
| export-data.md | Exporting tables, ranges and named ranges |
| import-data.md | Import CSV, DataTable, and other data sources into sheets |
| import-data-advanced.md | Import HTML tables, XML, arrays, collections, nested collections, DataColumn, DataView, grid controls |
| data-validation.md | Add and manage data validation rules and dropdowns |
| comments.md | Add, edit, and remove cell comments/notes |
| conditional-formatting.md | Apply conditional formatting rules and color scales |
| freeze-panes.md | Freeze rows, columns, split panes, and unfreeze worksheet sections |
| show-hide.md | Show/hide rows, columns, sheets, grid lines, headers, tabs, and zoom level |
| row-column-insert-delete.md | Insert, delete, and move rows and columns with formatting options |
| row-column-sizing.md | Resize, autofit, group, and subtotal rows and columns |
| auto-fill.md | Auto fill series, patterns, and trends in cell ranges |
| fill-series.md | Fill series with linear, growth, datetime, and auto fill options |
| find-all-replace.md | Find all by type (text, numbers, formulas, values, comments), replace with options, entire workbook |
| filtering-advanced.md | Top10 filters, custom conditions, combination (text/datetime), dynamic, color, icon filters, advanced filters |
| page-setup.md | Page setup, margins, headers/footers, print areas |
| pictures.md | Insert, position, resize, align pictures and images, external links, SVG images |
| pivot-table.md | Create and configure pivot tables |
| pivot-table-advanced.md | Advanced pivot operations: cell formatting, layouts, sorting/filtering, grouping, calculated fields |
| pivot-chart.md | Create and configure pivot charts from pivot table data |
| table-listobject.md | Create and manage Excel tables (ListObjects) |
| what-if-analysis.md | Create and manage scenarios with what-if analysis for testing input values |
| slicer.md | Create and manage table slicers for UI-based filtering |
| security.md | Password protection, encryption, and permission settings |
| drawing-objects.md | Create and manage drawing objects including text boxes, checkboxes, shapes, and comments |
| macros.md | Create, edit, and manage VBA macros in Excel workbooks |
| custom-xml.md | Add and read custom XML parts to store arbitrary XML data in workbooks |
| worksheet-move-copy.md | Move and copy worksheets, rows, columns, and cell ranges |
所有模板和片段都在文件夹中:
references/| 文件 | 内容 |
|---|---|
| nuget-packages.md | 按应用类型划分的NuGet包映射(模式1) |
| template.csx | 基础CSX脚本结构和许可证注册 |
| document-structure.md | 创建/保存/关闭工作簿、添加/重命名/删除/移动工作表 |
| template-markers.md | 模板标记绑定:变量、DataTable、列表、DataSet |
| cell-formatting.md | 单元格格式、数字格式、样式、自动调整 |
| cell-values.md | 单元格值与操作:设置/读取文本、数字、公式、日期、布尔值、检测类型 |
| cell-access-manipulation.md | 相对访问单元格、不连续区域、迁移区域、引用/从属单元格、清除内容 |
| formulas-advanced.md | 跨工作表引用、数组公式、外部引用、命名区域、计算列、计算模式、公式审核 |
| charts.md | 创建和配置图表 |
| excel-csv.md | 导入/导出CSV |
| excel-to-json.md | 将工作表或区域转换为JSON |
| excel-to-pdf.md | 使用渲染器将工作簿转换为PDF |
| export-data.md | 导出表格、区域和命名区域 |
| import-data.md | 将CSV、DataTable和其他数据源导入工作表 |
| import-data-advanced.md | 导入HTML表格、XML、数组、集合、嵌套集合、DataColumn、DataView、网格控件 |
| data-validation.md | 添加和管理数据验证规则与下拉列表 |
| comments.md | 添加、编辑和删除单元格批注/注释 |
| conditional-formatting.md | 应用条件格式规则和颜色刻度 |
| freeze-panes.md | 冻结行、列、拆分窗格,以及取消冻结工作表区域 |
| show-hide.md | 显示/隐藏行、列、工作表、网格线、页眉、标签和缩放级别 |
| row-column-insert-delete.md | 插入、删除和移动行与列,并提供格式选项 |
| row-column-sizing.md | 调整大小、自动调整、分组和分类汇总行与列 |
| auto-fill.md | 自动填充单元格区域的序列、模式和趋势 |
| fill-series.md | 用线性、增长、日期时间和自动填充选项填充序列 |
| find-all-replace.md | 按类型查找全部(文本、数字、公式、值、批注)、带选项的替换、整个工作簿范围 |
| filtering-advanced.md | 前10项筛选、自定义条件、组合(文本/日期时间)、动态、颜色、图标筛选、高级筛选 |
| page-setup.md | 页面设置、边距、页眉/页脚、打印区域 |
| pictures.md | 插入、定位、调整大小、对齐图片和图像、外部链接、SVG图像 |
| pivot-table.md | 创建和配置数据透视表 |
| pivot-table-advanced.md | 高级数据透视操作:单元格格式、布局、排序/筛选、分组、计算字段 |
| pivot-chart.md | 基于数据透视表数据创建和配置数据透视图 |
| table-listobject.md | 创建和管理Excel表格(ListObjects) |
| what-if-analysis.md | 创建和管理假设分析场景,用于测试输入值 |
| slicer.md | 创建和管理表格切片器,用于基于UI的筛选 |
| security.md | 密码保护、加密和权限设置 |
| drawing-objects.md | 创建和管理绘图对象,包括文本框、复选框、形状和批注 |
| macros.md | 在Excel工作簿中创建、编辑和管理VBA宏 |
| custom-xml.md | 添加和读取自定义XML部件,用于在工作簿中存储任意XML数据 |
| worksheet-move-copy.md | 移动和复制工作表、行、列和单元格区域 |
Rules
规则
- Output files go in directory
./output/ - Temp scripts must be created inside
.csx— never in the workspace root or customer{skill-root}/syncfusion-dotnet-excel/scripts/folderscripts/ - Use license key from at workspace root or env var
SyncfusionLicense.txtSYNCFUSION_LICENSE_KEY - Never use Python libraries (e.g., openpyxl, pandas)
- Never leave temp files after execution
.csx
- 输出文件存放在目录
./output/ - 临时脚本必须创建在
.csx内——绝不能在工作区根目录或客户的{skill-root}/syncfusion-dotnet-excel/scripts/文件夹中创建scripts/ - 使用工作区根目录中的许可证密钥,或环境变量
SyncfusionLicense.txtSYNCFUSION_LICENSE_KEY - 绝不能使用Python库(如openpyxl、pandas)
- 执行完成后绝不能保留临时文件
.csx