Chsword.Excel2Object.Cli
2.8.1
dotnet tool install --global Chsword.Excel2Object.Cli --version 2.8.1
dotnet new tool-manifest
dotnet tool install --local Chsword.Excel2Object.Cli --version 2.8.1
#tool dotnet:?package=Chsword.Excel2Object.Cli&version=2.8.1
nuke :add-package Chsword.Excel2Object.Cli --version 2.8.1
excel2obj
Command-line companion to Excel2Object: convert Excel workbooks to JSON and back, and generate C# model classes from a sheet.
dotnet tool install -g Chsword.Excel2Object.Cli
Excel → JSON
excel2obj convert orders.xlsx # prints a JSON array to stdout
excel2obj convert orders.xlsx --output orders.json # writes the file
excel2obj convert orders.xlsx --sheet Orders --typed
excel2obj convert a.xlsx b.xls --output ./json/ # several inputs need an output directory
Each row becomes an object keyed by the header row. Values are the cell text (formulas are evaluated); with
--typed, a column whose non-empty values are all integers, decimals, TRUE/FALSE or ISO dates is emitted as
JSON numbers, booleans or yyyy-MM-ddTHH:mm:ss strings, and empty cells become null.
JSON → Excel
excel2obj convert orders.json --output orders.xlsx
excel2obj convert orders.json --output orders.xls --sheet Orders
The input must be a JSON array of flat objects. Columns are the union of all keys in first-seen order; a column
whose values are all numbers or all booleans is written as numeric / boolean cells, null as blank cells, nested
objects and arrays as their JSON text.
Generate a model class
excel2obj generate-model orders.xlsx # prints the class
excel2obj generate-model orders.xlsx --output Order.cs --class Order --namespace My.App
produces something like
using System;
using Chsword.Excel2Object;
namespace My.App;
public class Order
{
[ExcelTitle("Product")]
public string? Product { get; set; }
[ExcelTitle("Qty")]
public int Qty { get; set; }
[ExcelTitle("Unit Price")]
public decimal? UnitPrice { get; set; }
}
Types are inferred from the data (bool, int, long, decimal, DateTime, otherwise string) and become
nullable when the column has empty cells. Titles are turned into PascalCase identifiers; any Unicode letters are kept.
Exit codes
0 success, 1 usage error (message on stderr followed by help), 2 the conversion itself failed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.