Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meineglock20/listtotabledisplay
The List to Table Formatter for .NET is a versatile library designed to convert lists of objects into well-formatted table displays . Ideal for web applications and console applications - including log files and word documents.
https://github.com/meineglock20/listtotabledisplay
asp-net asp-net-core console csharp data display dotnet formatter html list logging netstandard20 object-list presentation razor-pages table table-formatter text-table text-to-table utility
Last synced: 22 days ago
JSON representation
The List to Table Formatter for .NET is a versatile library designed to convert lists of objects into well-formatted table displays . Ideal for web applications and console applications - including log files and word documents.
- Host: GitHub
- URL: https://github.com/meineglock20/listtotabledisplay
- Owner: meineGlock20
- Created: 2024-09-25T13:35:23.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-24T20:25:55.000Z (29 days ago)
- Last Synced: 2024-11-24T20:49:24.669Z (29 days ago)
- Topics: asp-net, asp-net-core, console, csharp, data, display, dotnet, formatter, html, list, logging, netstandard20, object-list, presentation, razor-pages, table, table-formatter, text-table, text-to-table, utility
- Language: C#
- Homepage:
- Size: 250 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# List to Table Formatter for .NET
For Console Applications and Logging
The List to Table Formatter for .NET is a versatile library designed to convert lists of objects into well-formatted table displays. It supports customizable padding, border styles, and header text styles to enhance readability. Ideal for console applications and logging, this library ensures your data is presented in a clear and structured manner.
For Web Applications
Easily converts a list of objects into an HTML table for web applications.
The List to Table Formatter for .NET generates clean and responsive tables that can be styled with a popular framework like Bootstrap or your own CSS to match your website's design.## Installation
You can install the lastest package via NuGet:
```
dotnet add package MeineGlock.ListToTableDisplay --version 1.1.0
```## Usage
### Console Application
Basic example of how to use the List to Table Formatter in a console application:
See the ConsoleDemo for more advanced implementation.```csharp
using ListToTableDisplay;var people = new List
{
new() { Name = "John", Age = 25, City = "New York" },
new() { Name = "Jane", Age = 27, City = "Chicago" },
new() { Name = "Tom", Age = 30, City = "Los Angeles" },
new() { Name = "Lucy", Age = 35, City = "San Francisco" }
};ListToTableDisplay listToTableDisplay = new();
// Cast to an object list and pass to the DisplayTable method.
Console.WriteLine(listToTableDisplay.DisplayTable(people.Cast().ToList()));
```
### Web ApplicationBasic example of how to use the List to Table Formatter in a ASP.NET RAZOR web application:
See the WebDemo for more information.
```csharp
// Create a property for the generated table.
public string? GeneratedTable { get; set; }// In the OnGet method, create a list of objects and generate the table.
public async Task OnGetAsync()
{
// Create a list of objects.
var people = new List
{
new() { Name = "John", Age = 25, City = "New York" },
new() { Name = "Jane", Age = 27, City = "Chicago" },
new() { Name = "Tom", Age = 30, City = "Los Angeles" },
new() { Name = "Lucy", Age = 35, City = "San Francisco" }
};// Pass your list to the DisplayTable method and display the table.
var htmlTable = ListToTableDisplay.ListToHtmlTableDisplay.DisplayTable(
people
.Cast()
.ToList()
, ListToTableDisplay.HeaderTextStyle.SplitPascalCase, minify: false, tableClass: "table table-striped table-hover", tableId: "peopleTable");// Set the generated table to the property to display in the Razor Page.
GeneratedTable = htmlTable;
}
```
```html@page
@model WebApplicationDemo.Pages.IndexModel
@{
}
Web Application Demo
@* This is where the table will be displayed *@
@Html.Raw(Model.GeneratedTable)
```
## Customization Options for Console Applications
You can customize the table display by setting various properties on the `TableDisplay` object. For example, you can change the padding, border style, and header text style:
```csharp
ListToTableDisplay.ListToTableDisplay listToTableDisplay = new()
{
// Left and right paddding. Value of 1 to 10, 1 is the default.
Padding = 1,
// Split the header text by PascalCase or underscore. None is the default.
HeaderTextStyle = ListToTableDisplay.HeaderTextStyle.SplitPascalCase,
// Set the border style to classic or modern. Modern is the default.
BorderStyle = ListToTableDisplay.BorderStyle.Classic,
};
```
## Formatting Notes for Console Applications
- A monospaced font is required for proper table formatting.
- UTF-8 encoding is required for the modern table format to display correctly.
- If your console is not formatting the modern table correctly, try setting the console to output UTF-8.
```
Console.OutputEncoding = System.Text.Encoding.UTF8;
```## Output Examples
### Terminal
![Screenshot 2024-09-28 102758](https://github.com/meineGlock20/ListToTableDisplay/blob/main/images/Screenshot%202024-09-28%20102758.png)### Notepad
![Screenshot 2024-09-28 084009](https://github.com/meineGlock20/ListToTableDisplay/blob/main/images/Screenshot%202024-09-28%20084009.png)### Word
![Screenshot 2024-09-28 084532](https://github.com/meineGlock20/ListToTableDisplay/blob/main/images/Screenshot%202024-09-28%20084532.png)### HTML Table
![Screenshot 2024-11-24 111823](https://github.com/meineGlock20/ListToTableDisplay/blob/main/images/Screenshot%202024-11-24%20111823.png)## Release Notes
- 1.1.0 - 2024-11-24 - Added the ability to display a list of objects as an HTML table for web applications.
- 1.0.3 - 2024-11-10 - Fixed an issue where a null value in the list would cause an exception.
- 1.0.2 - 2024-09-30 - Internal improvements.
- 1.0.1 - 2024-09-30 - Internal improvements.
- 1.0.0 - 2024-09-29 - Initial release.## Home Page
https://github.com/meineGlock20/ListToTableDisplay## License
This project is licensed under the MIT License.
![](https://img.shields.io/badge/License-MIT-blue.svg)
https://github.com/meineGlock20/ListToTableDisplay/blob/main/ListToTableDisplay/LICENSE