Excel To C# Model

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert Excel to C# Model online — paste, edit, and download C# class.

Namespace:
Class Name:
Access Modifier:
public internal
Property Naming:
PascalCase camelCase Original
Primary Key:
Add [Key] attribute to matching property
Data Annotations:
Add [Key], [Column], [Required] attributes
Nullable Types:
Use int?, DateTime? for nullable columns
Indent:
4 Spaces 2 Spaces Tab
Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

What Is a C# Model Class?

A C# model class (also called a POCO — Plain Old CLR Object) is a C# class that represents a data entity with properties mapping to database columns or API fields. Model classes are the foundation of .NET application architectures including:  

  • Entity Framework (EF Core) — Code First approach where C# classes define the database schema.

  • ASP.NET Core MVC / Web API — ViewModels and DTOs for request/response handling.

  • Domain-Driven Design (DDD) — Domain entities encapsulating business logic.

  • Serialization — Objects mapped to JSON, XML, or other formats for APIs and storage.

Microsoft's official C# documentation is available at Microsoft Learn C# Guide. Entity Framework documentation is at Microsoft Learn EF Core.  

What Is Excel to C# Model Converter?

Excel to C# Model is a free online tool that converts spreadsheet column definitions from Excel files (.xlsx, .xls, .xlsm) into C# model class code. Each column in your spreadsheet becomes a property in the generated C# class, with automatic type inference and optional Entity Framework Data Annotations. The tool processes everything in your browser — your files are never uploaded to any server.  

Core Features

  • Namespace and Class Name — Define the namespace and class name for the generated C# file.

  • Access Modifiers — Choose public or internal for the class.

  • Property Naming Conventions — Convert column names to PascalCase (C# standard), camelCase (JSON serialization), or keep Original names.

  • Primary Key Support — Specify a column name to add the [Key] attribute for Entity Framework.

  • Data Annotations — Automatically add [Key], [Column], and [Required] attributes for Entity Framework Code First.

  • Nullable Reference Types — Use int?, DateTime?, decimal? for columns that may contain null values.

  • Automatic Type Inference — The tool infers C# types (int, string, decimal, DateTime, bool) from your data.

  • Indentation Control — Choose 4-space (C# default), 2-space, or tab indentation.

  • Built-in Table Editor — Edit cells, transpose, deduplicate, and transform data before generation.

  • 100% Client-Side Processing — No data leaves your device.

How to Use Excel to C# Model?

Step 1: Upload or Enter Your Data

Drag and drop an Excel file (.xlsx, .xls, or .xlsm) onto the upload area, or click to browse. Alternatively, click Enter Data to type column definitions manually.  

Step 2: Edit Your Data (Optional)

After loading, your data appears in an editable table. Use the toolbar to modify cells, add or remove rows and columns, transpose data, remove duplicates and empty rows, change text case, or find and replace values. Toggle First Row as Header to define column names.  

Step 3: Configure C# Options

In the Properties panel on the right:  

  • Namespace — Enter your project's namespace (e.g., MyApp.Models).

  • Class Name — Enter the class name (e.g., Product, Customer).

  • Access Modifier — Choose public (accessible from other projects) or internal (project-only).

  • Property NamingPascalCase for standard C# properties, camelCase for JSON/JavaScript interop, or Original to keep column names as-is.

  • Primary Key — Enter the column name that should receive the [Key] attribute (e.g., Id).

  • Data Annotations — Enable to add [Key], [Column("name")], and [Required] attributes for Entity Framework.

  • Nullable Types — Enable to use nullable value types (int?, DateTime?) for columns with empty values.

  • Indent — 4 Spaces (C# convention), 2 Spaces, or Tab.

Conversion Example

Given this Excel table with column headers:

IdProduct NamePriceCreated AtIs Active
1Widget A29.992025-01-15true

With Data Annotations enabled and Primary Key set to "Id", the tool generates:

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MyApp.Models{
   [Table("Products")]
   public class Product
   {
       [Key]
       [Column("Id")]
       public int Id { get; set; }

       [Required]
       [Column("Product Name")]
       public string ProductName { get; set; }

       [Column("Price")]
       public decimal Price { get; set; }

       [Column("Created At")]
       public DateTime CreatedAt { get; set; }

       [Column("Is Active")]
       public bool IsActive { get; set; }
   }
}

Step 4: Convert and Copy

Click Convert to generate the C# code. The output appears in the Output Data panel. Click Copy to Clipboard to copy it into your .NET project. Click Restart to start over.  

C# Type Mapping Reference

Excel Data PatternC# TypeNullable
Whole numbers (1, 42, 100)intint?
Decimals (3.14, 29.99)decimaldecimal?
Text ("hello", "ABC123")stringstring (always nullable)
Dates (2025-01-15)DateTimeDateTime?
Booleans (true, false)boolbool?

Common Use Cases

  • Entity Framework Code First — Generate POCO entity classes from spreadsheet-defined database schemas for rapid EF Core prototyping.

  • API DTOs — Create Data Transfer Objects from Excel API specification documents for ASP.NET Core Web API projects.

  • Database Migration — Generate C# models matching legacy database tables documented in Excel spreadsheets.

  • ViewModels — Create ASP.NET MVC ViewModels from UI specification sheets.

  • Configuration Models — Generate strongly-typed configuration classes from Excel-based configuration documentation.

  • Unit Test Data — Create model classes for test fixtures defined in test specification spreadsheets.

  • Documentation — Keep data model documentation in Excel and regenerate C# code when the schema evolves.

Frequently Asked Questions (FAQ)

  • Is my Excel data uploaded to a server?

    No. All file parsing and C# code generation happens entirely in your browser using client-side JavaScript. Your files are never uploaded, transferred, or stored on any server. The tool works offline once the page has loaded.

  • What Excel file formats are supported?

    The tool supports .xlsx (Excel 2007+), .xls (Excel 97-2003), and .xlsm (macro-enabled) files. Multi-sheet workbooks are supported — use the sheet selector to choose which sheet to convert.

  • What are Data Annotations and when should I use them?

    Data Annotations are C# attributes (like [Key], [Column], [Required]) from the System.ComponentModel.DataAnnotations namespace. They are used by Entity Framework to configure database mapping, validation rules, and table-column relationships. Enable Data Annotations when generating EF Core entity classes. Disable them for plain POCOs, DTOs, or ViewModels that don't need database mapping.

  • Should I use PascalCase or camelCase for properties?

    PascalCase is the C# standard for public properties (e.g., ProductName). Use it for Entity Framework entities, domain models, and most .NET code. camelCase (e.g., productName) is common for JSON serialization in ASP.NET Core APIs (configured via JsonSerializerOptions). Original preserves your exact column names, useful when they already follow your naming convention.

  • When should I enable nullable types?

    Enable nullable types when your spreadsheet has empty cells in numeric or date columns. Without nullable types, the tool uses int, DateTime, etc. — which cannot be null in C#. With nullable types enabled, it generates int?, DateTime? to properly handle missing values. Note: string is always nullable in C# regardless of this setting.

  • How does the tool infer C# types from Excel data?

    The tool analyzes the data in each column to determine the most specific C# type that fits all values: whole numbers → int, decimals → decimal, dates → DateTime, booleans → bool, everything else → string. If a column contains mixed types, it falls back to string.

  • Can I use this with .NET 8 / .NET 9?

    Yes. The generated C# code uses standard C# syntax compatible with all modern .NET versions (.NET 6+, .NET 7, .NET 8, .NET 9). The POCO classes and Data Annotations work with Entity Framework Core 6+ and ASP.NET Core.

  • Can I edit the data before converting?

    Yes. After uploading your file, the built-in table editor lets you modify cell values, add or remove rows and columns, transpose data, remove duplicates and empty rows, change text case, and find-and-replace — all before generating the C# code.

  • What is the difference between public and internal access modifiers?

    public makes the class accessible from any other project that references the assembly. internal restricts access to within the same assembly (project). Use public for shared model libraries and internal for project-specific models that shouldn't be exposed outside the assembly.

  • Can I use this tool without uploading a file?

    Yes. Click the Enter Data button to open a blank editor where you can type or paste column definitions manually, then generate the C# class.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.

Excel To JSON

Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.
Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.

Excel To CSV

Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.
Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.

Excel To SQL

Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.
Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.

Excel To ASCII Table

Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.