syncfusion-dotnet-excel

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Excel (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

前提条件

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
    ,
    Program.cs
    , etc.) and use the detection signals table in
    references/nuget-packages.md
    to identify the application type.
  • Look up the correct package(s) from
    references/nuget-packages.md
    based on the detected app type and tell the user to install them before generating any code.
  • 检查工作区项目文件(
    .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
    references/*.md
    file(s) for the requested feature
  • 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 /
      .Net.Core
      snippets
  • Do not create or run any
    .csx
    script

不得发明、猜测或使用参考文件中未明确提及的任何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
.xlsx
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.,
output/report.xlsx
,
~/Documents/sales.xlsx
,
/tmp/data.xlsx
).
Workflow:
仅当用户明确要求执行、生成文件或生成完整输出(如已完成的XLSX文件)时,使用此模式。
触发关键词: "create a workbook"、"create an Excel file"、"generate a spreadsheet"、"make a spreadsheet"、"generate a file"、"open"、"edit"、"modify"、"change" an
.xlsx
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",或当用户提供文件路径时(如
output/report.xlsx
~/Documents/sales.xlsx
/tmp/data.xlsx
)。
工作流:

Step 1 — Create Temp CSX Script

步骤1 — 创建临时CSX脚本

  • Start with
    references/template.csx
    as the base
  • Create at:
    {skill-root}/syncfusion-dotnet-excel/scripts/temp-{timestamp}.csx
    (e.g.,
    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
    references/*.md
    file(s) and extract code snippets
  • 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
    .csx
    file after execution
  • Report SUCCESS/ERROR with output file path(s) and any error messages with fixes

  • 执行完成后删除临时
    .csx
    文件
  • 报告执行成功/失败,并提供输出文件路径及错误信息与修复建议

Code References

代码参考

All templates and snippets are in the
references/
folder:
FileContents
nuget-packages.mdNuGet package mappings by application type (Mode 1)
template.csxBase CSX script structure and license registration
document-structure.mdCreate/save/close workbook, add/rename/delete/move sheets
template-markers.mdTemplate marker binding: variables, DataTable, lists, DataSet
cell-formatting.mdCell formatting, number formats, styles, autofit
cell-values.mdCell values and operations: set/read text, numbers, formulas, dates, booleans, detect type
cell-access-manipulation.mdAccess cells relatively, discontinuous ranges, migrant range, precedent/dependent cells, clear content
formulas-advanced.mdCross-sheet references, array formulas, external references, named ranges, calculated columns, calculation modes, formula auditing
charts.mdCreate and configure charts
excel-csv.mdImport/export CSV
excel-to-json.mdConvert worksheets or ranges to JSON
excel-to-pdf.mdConvert workbook to PDF using renderer
export-data.mdExporting tables, ranges and named ranges
import-data.mdImport CSV, DataTable, and other data sources into sheets
import-data-advanced.mdImport HTML tables, XML, arrays, collections, nested collections, DataColumn, DataView, grid controls
data-validation.mdAdd and manage data validation rules and dropdowns
comments.mdAdd, edit, and remove cell comments/notes
conditional-formatting.mdApply conditional formatting rules and color scales
freeze-panes.mdFreeze rows, columns, split panes, and unfreeze worksheet sections
show-hide.mdShow/hide rows, columns, sheets, grid lines, headers, tabs, and zoom level
row-column-insert-delete.mdInsert, delete, and move rows and columns with formatting options
row-column-sizing.mdResize, autofit, group, and subtotal rows and columns
auto-fill.mdAuto fill series, patterns, and trends in cell ranges
fill-series.mdFill series with linear, growth, datetime, and auto fill options
find-all-replace.mdFind all by type (text, numbers, formulas, values, comments), replace with options, entire workbook
filtering-advanced.mdTop10 filters, custom conditions, combination (text/datetime), dynamic, color, icon filters, advanced filters
page-setup.mdPage setup, margins, headers/footers, print areas
pictures.mdInsert, position, resize, align pictures and images, external links, SVG images
pivot-table.mdCreate and configure pivot tables
pivot-table-advanced.mdAdvanced pivot operations: cell formatting, layouts, sorting/filtering, grouping, calculated fields
pivot-chart.mdCreate and configure pivot charts from pivot table data
table-listobject.mdCreate and manage Excel tables (ListObjects)
what-if-analysis.mdCreate and manage scenarios with what-if analysis for testing input values
slicer.mdCreate and manage table slicers for UI-based filtering
security.mdPassword protection, encryption, and permission settings
drawing-objects.mdCreate and manage drawing objects including text boxes, checkboxes, shapes, and comments
macros.mdCreate, edit, and manage VBA macros in Excel workbooks
custom-xml.mdAdd and read custom XML parts to store arbitrary XML data in workbooks
worksheet-move-copy.mdMove 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
    ./output/
    directory
  • Temp
    .csx
    scripts must be created inside
    {skill-root}/syncfusion-dotnet-excel/scripts/
    — never in the workspace root or customer
    scripts/
    folder
  • Use license key from
    SyncfusionLicense.txt
    at workspace root or env var
    SYNCFUSION_LICENSE_KEY
  • Never use Python libraries (e.g., openpyxl, pandas)
  • Never leave temp
    .csx
    files after execution
  • 输出文件存放在
    ./output/
    目录
  • 临时
    .csx
    脚本必须创建在
    {skill-root}/syncfusion-dotnet-excel/scripts/
    内——绝不能在工作区根目录或客户的
    scripts/
    文件夹中创建
  • 使用工作区根目录
    SyncfusionLicense.txt
    中的许可证密钥,或环境变量
    SYNCFUSION_LICENSE_KEY
  • 绝不能使用Python库(如openpyxl、pandas)
  • 执行完成后绝不能保留临时
    .csx
    文件