https://github.com/datajuggler/blazor.excelerate
This Blazor project uses DataJuggler.Blazor.Components and DataJuggler.Excelerate to code generate C# classes from Excel worksheets
https://github.com/datajuggler/blazor.excelerate
Last synced: over 1 year ago
JSON representation
This Blazor project uses DataJuggler.Blazor.Components and DataJuggler.Excelerate to code generate C# classes from Excel worksheets
- Host: GitHub
- URL: https://github.com/datajuggler/blazor.excelerate
- Owner: DataJuggler
- Created: 2021-10-13T04:24:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-12T10:04:46.000Z (over 1 year ago)
- Last Synced: 2025-03-16T05:31:55.184Z (over 1 year ago)
- Language: C#
- Size: 11.5 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
5.18.2024: New Video
First Ever Opensource Saturday - Sunday Edition
https://youtu.be/uxa1xR6xpzk
7.24.2023: New Video
The Best C# Excel Library In The Galaxy
https://youtu.be/uWXiz52cqlg

Code Generate C# Classes From Excel Header Rows

Live Demo:
https://excelerate.datajuggler.com
Blazor Excelerate is an open source Blazor demo for Nuget DataJuggler.Excelerate, which is built on top of NPOI.
Instructions (copied from Index.razor.cs)
1. Prepare your spreadsheet (save as .xlsx extension) and ensure you have a header row, and the column names make good property names.
Download MemberData.xlsx to see an example (Downloads\MemberData.xlsx comes with this project and contains 20,000 random names and addresses).
2. Click the Upload button to upload your spreadsheet and select the sheet to code generate a class for.

3. Type in a namespace for your project and select the sheet in the Sheets ComboBox then click the 'Generate Class' button.

4. Download the zip file and extract the contents to get your C# file.

Tips / Troubleshooting
It helps to have some rows of data to attempt to determine the data type. Getting the data type is kind of a hack.
# News
Update 7.24.2023:
I created a WinForms (desktop) app that can be installed via NuGet and the dotnet CLI
To Install Via Nuget and DOT NET CLI, navigate to the folder you wish to create your project in
cd c:\Projects\ExcelerateWinApp
dotnet new install DataJuggler.ExcelerateWinApp
dotnet new DataJuggler.ExcelerateWinApp
or
Clone this project from GitHub https://github.com/DataJuggler/ExcelerateWinApp
# Setup Instructions for ExcelerateWinApp, copied from the above project.
1. Create one or more classes from Excel Header Rows at
Blazor Excelerate
https://excelerate.datajuggler.com
Download the file MemberData.xlsx from the above site to see an example.
Use ExcelerateWinApp.Objects for the namespace or rename this project to your liking
2. Copy the classes created into the Objects folder of ExcelerateWinApp
3. Load Excel Worksheet(s) - Example is included in the UpdateButton_Click event
// load your object(s)
string workbookPath = FileSelector.Text;
// Example WorksheetInfo objects
WorksheetInfo info = new WorksheetInfo();
info.LoadColumnOptions = LoadColumnOptionsEnum.LoadAllColumnsExceptExcluded;
info.Path = workbookPath;
// Set your SheetName
info.SheetName = "Address";
// Example WorksheetInfo objects
WorksheetInfo info2 = new WorksheetInfo();
info2.LoadColumnOptions = LoadColumnOptionsEnum.LoadAllColumnsExceptExcluded;
info2.Path = workbookPath;
// Set the SheetName for info2
info2.SheetName = 'States";
// Example load Worksheets
Worksheet addressWorksheet = ExcelDataLoader.LoadWorksheet(workbookPath, info);
Worksheet statesWorksheet = ExcelDataLoader.LoadWorksheet(workbookPath, info2);
5. Load your list of objects
// Examples loading the Address and States sheet from MemberData.xlsx
List
addresses = Address.Load(addressWorksheet);
List states = States.Load(statesWorksheet);
6. Perform updates on your List of objects
For this example, I inserted a column StateName into the Address sheet in Excel and
added a few state names manually. You must add a few entries so the data type can be
attempted to be determined. Then I code generated Address and States classes using
Blazor Excelerate
https://excelerate.datajuggler.com
This method set the Address.StateName for each row by looking up the State Name by StateId
///
/// Lookup the StateName for each Address object by StateId
///
public void FixStateNames(ref List
addresses, List states)
{
// verify both lists exists and have at least one item
if (ListHelper.HasOneOrMoreItems(addresses, states))
{
// Iterate the collection of Address objects
foreach (Address address in addresses)
{
// get a local copy
int stateId = address.StateId;
// set the stateName
address.StateName = states.Where(x => x.Id == stateId).FirstOrDefault().Name;
// Increment the value for Graph
Graph.Value++;
// update the UI every 100
if (Graph.Value % 100 == 0)
{
Refresh();
Application.DoEvents();
}
}
}
}
7. Save your worksheet back to Excel
// resetup the graph
Graph.Maximum = addresses.Count;
Graph.Value = 0;
// change the text
StatusLabel.Text = "Saving Addresses please wait...";
// you must convert the list objects to List before it can be saved
List excelerateObjectList = addresses.Cast().ToList();
// Now save the worksheet
SaveWorksheetResponse response = ExcelHelper.SaveWorksheet(excelerateObjectList, addressWorksheet, info, SaveWorksheetCallback, 500);
8. (Optional) Leave a Star on DataJuggler.Excelerate, Blazor Excelerate or this project on GitHub
DataJuggler.Excelerate
https://github.com/DataJuggler/Excelerate
Blazor Excelerate
https://github.com/DataJuggler/Blazor.Excelerate
Excelerate Win App
https://github.com/DataJuggler/ExcelerateWinApp
9. (Optional) Subscribe to my YouTube channel
https://youtube.com/DataJuggler