{"id":29600731,"url":"https://github.com/fjeremic/datatableprettyprinter","last_synced_at":"2025-07-20T12:36:53.258Z","repository":{"id":117214365,"uuid":"260086128","full_name":"fjeremic/DataTablePrettyPrinter","owner":"fjeremic","description":"An extension library of System.Data.DataTable which provides extension methods for fully customizable pretty-printing of DataTable to an ASCII formatted string which can be displayed on the console or any text buffer.","archived":false,"fork":false,"pushed_at":"2020-05-05T23:08:22.000Z","size":27,"stargazers_count":17,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-12T22:36:08.389Z","etag":null,"topics":["console","datatable","pretty-print","prettyprint","print","sql"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fjeremic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-30T01:34:55.000Z","updated_at":"2025-05-27T17:05:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd241b13-04c9-47c7-a7c4-492533a35191","html_url":"https://github.com/fjeremic/DataTablePrettyPrinter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fjeremic/DataTablePrettyPrinter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjeremic%2FDataTablePrettyPrinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjeremic%2FDataTablePrettyPrinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjeremic%2FDataTablePrettyPrinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjeremic%2FDataTablePrettyPrinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fjeremic","download_url":"https://codeload.github.com/fjeremic/DataTablePrettyPrinter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjeremic%2FDataTablePrettyPrinter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266127267,"owners_count":23880425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console","datatable","pretty-print","prettyprint","print","sql"],"created_at":"2025-07-20T12:36:37.990Z","updated_at":"2025-07-20T12:36:53.251Z","avatar_url":"https://github.com/fjeremic.png","language":"C#","readme":"# DataTablePrettyPrinter\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/fjeremic/DataTablePrettyPrinter/blob/master/LICENSE)\n[![Build Status](https://dev.azure.com/fjeremic/DataTablePrettyPrinter/_apis/build/status/fjeremic.DataTablePrettyPrinter?branchName=master)](https://dev.azure.com/fjeremic/DataTablePrettyPrinter/_build/latest?definitionId=6\u0026branchName=master)\n\nAn extension library of System.Data.DataTable which provides extension methods for fully customizable pretty-printing of DataTables to an ASCII formatted string which can be displayed on the console or any text buffer.\n\n## Installing / Getting started\n\nThe best way to obtain the library is via the [DataTablePrettyPrinter NuGet package](https://www.nuget.org/packages/DataTablePrettyPrinter/):\n \n```shell\ndotnet add package DataTablePrettyPrinter\n```\n\nAlternatively you may clone this git repository and build the library for use within your projects:\n\n```shell\ndotnet build\n```\n\n## Visual Overview\n\nThe following mock table is an overview of the different areas of the `DataTable` which are displayed. The `TableName` and `ColumnName` values map directly onto their `DataTable.TableName` and `DataColumn.ColumnName` properties. The data area displays the row contents of the table.\n\n```\n+---------------------------------------------------+\n|                     TableName                     |\n+------------+------------+------------+------------+\n| ColumnName | ColumnName | ColumnName | ColumnName |\n+------------+------------+------------+------------+\n|            |            |            |            |\n|            |            |            |            |\n|    Data    |    Data    |    Data    |    Data    |\n|    Area    |    Area    |    Area    |    Area    |\n|            |            |            |            |\n|            |            |            |            |\n+------------+------------+------------+------------+\n```\n\n## Examples\n\nTo demonstrate the capabilities and ease of use of this library we will use a simple data table:\n\n```csharp\nusing DataTablePrettyPrinter;\n\nDataTable table = new DataTable(\"Prescriptions\");\n\ntable.Columns.Add(\"Dosage\", typeof(Int32));\ntable.Columns.Add(\"Drug\", typeof(String));\ntable.Columns.Add(\"Patient\", typeof(String));\ntable.Columns.Add(\"Date\", typeof(DateTime));\n\ntable.Rows.Add(25, \"Indocin\", \"David\", DateTime.Parse(\"5/1/2008 12:30:52 PM\"));\ntable.Rows.Add(50, \"Enebrel\", \"Sam\", DateTime.Parse(\"9/11/2008 8:42:30 AM\"));\ntable.Rows.Add(10, \"Hydralazine\", \"Christoff\", DateTime.Parse(\"12/12/2019 9:15:00 AM\"));\ntable.Rows.Add(21, \"Combivent\", \"Janet\", DateTime.Parse(\"12/8/2018 3:00:00 PM\"));\ntable.Rows.Add(100, \"Dilantin\", \"Melanie\", DateTime.Parse(\"9/14/2020 4:44:44 PM\"));\n```\n\n### Default pretty printing\n\nDefault pretty printing is as easy as calling the `ToPrettyPrintedString` extension method:\n\n```csharp\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+-----------------------------------------------------------+\n|                       Prescriptions                       |\n+--------+-------------+-----------+------------------------+\n| Dosage |    Drug     |  Patient  |          Date          |\n+--------+-------------+-----------+------------------------+\n| 25     | Indocin     | David     | 2008-05-01 12:30:52 PM |\n| 50     | Enebrel     | Sam       | 2008-09-11 8:42:30 AM  |\n| 10     | Hydralazine | Christoff | 2019-12-12 9:15:00 AM  |\n| 21     | Combivent   | Janet     | 2018-12-08 3:00:00 PM  |\n| 100    | Dilantin    | Melanie   | 2020-09-14 4:44:44 PM  |\n+--------+-------------+-----------+------------------------+\n```\n\n### Controlling borders\n\nBorders of the entire table or individual columns can be fully controlled. The library allows you to specify borders with a flags `enum`. We can for example disable drawing of side columns:\n\n\n```csharp\ntable.SetBorder(Border.Top | Border.Left);\n\ntable.Columns[0].SetHeaderBorder(Border.Top);\ntable.Columns[1].SetHeaderBorder(Border.Bottom | Border.Left);\ntable.Columns[2].SetHeaderBorder(Border.Bottom | Border.Left);\ntable.Columns[3].SetHeaderBorder(Border.Bottom | Border.Left);\n\ntable.Columns[0].SetDataBorder(Border.None);\ntable.Columns[1].SetDataBorder(Border.Left);\ntable.Columns[2].SetDataBorder(Border.Left);\ntable.Columns[3].SetDataBorder(Border.Left);\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n\n                        Prescriptions\n         +             +           +\n  Dosage |    Drug     |  Patient  |          Date\n+--------+-------------+-----------+------------------------+\n  25     | Indocin     | David     | 2008-05-01 12:30:52 PM\n  50     | Enebrel     | Sam       | 2008-09-11 8:42:30 AM\n  10     | Hydralazine | Christoff | 2019-12-12 9:15:00 AM\n  21     | Combivent   | Janet     | 2018-12-08 3:00:00 PM\n  100    | Dilantin    | Melanie   | 2020-09-14 4:44:44 PM\n         +             +           +\n```\n\nWe can also showcase the type of flexibility the library allows:\n\n```csharp\ntable.SetBorder(Border.Top | Border.Left);\n\ntable.Columns[0].SetHeaderBorder(Border.None);\ntable.Columns[1].SetHeaderBorder(Border.Left | Border.Top | Border.Right);\ntable.Columns[2].SetHeaderBorder(Border.None);\ntable.Columns[3].SetHeaderBorder(Border.Left | Border.Top);\n\ntable.Columns[0].SetDataBorder(Border.Bottom | Border.Right);\ntable.Columns[1].SetDataBorder(Border.None);\ntable.Columns[2].SetDataBorder(Border.Left | Border.Bottom);\ntable.Columns[3].SetDataBorder(Border.Left);\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+-----------------------------------------------------------+\n|                       Prescriptions\n|        +-------------+           +------------------------+\n| Dosage |    Drug     |  Patient  |          Date\n|        +             +           +\n| 25     | Indocin     | David     | 2008-05-01 12:30:52 PM\n| 50     | Enebrel     | Sam       | 2008-09-11 8:42:30 AM\n| 10     | Hydralazine | Christoff | 2019-12-12 9:15:00 AM\n| 21     | Combivent   | Janet     | 2018-12-08 3:00:00 PM\n| 100    | Dilantin    | Melanie   | 2020-09-14 4:44:44 PM\n+--------+             +-----------+\n```\n\n### Controlling the display of table name and column headers\n\nWe can fully control whether to display the table name, or each individual column header:\n\n\n```csharp\ntable.SetShowTableName(false);\n\ntable.Columns[1].SetShowColumnName(false);\ntable.Columns[3].SetShowColumnName(false);\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+--------+-------------+-----------+------------------------+\n| Dosage |             |  Patient  |                        |\n+--------+-------------+-----------+------------------------+\n| 25     | Indocin     | David     | 2008-05-01 12:30:52 PM |\n| 50     | Enebrel     | Sam       | 2008-09-11 8:42:30 AM  |\n| 10     | Hydralazine | Christoff | 2019-12-12 9:15:00 AM  |\n| 21     | Combivent   | Janet     | 2018-12-08 3:00:00 PM  |\n| 100    | Dilantin    | Melanie   | 2020-09-14 4:44:44 PM  |\n+--------+-------------+-----------+------------------------+\n```\n\n### Controlling text alignment of column names and data\n\nThe library has support for controlling text alignment:\n\n\n```csharp\ntable.SetTitleTextAlignment(TextAlignment.Left);\n\ntable.Columns[0].SetColumnNameAlignment(TextAlignment.Right);\ntable.Columns[1].SetColumnNameAlignment(TextAlignment.Left);\n\ntable.Columns[0].SetDataAlignment(TextAlignment.Center);\ntable.Columns[2].SetDataAlignment(TextAlignment.Right);\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+-----------------------------------------------------------+\n| Prescriptions                                             |\n+--------+-------------+-----------+------------------------+\n| Dosage | Drug        |  Patient  |          Date          |\n+--------+-------------+-----------+------------------------+\n|   25   | Indocin     |     David | 2008-05-01 12:30:52 PM |\n|   50   | Enebrel     |       Sam | 2008-09-11 8:42:30 AM  |\n|   10   | Hydralazine | Christoff | 2019-12-12 9:15:00 AM  |\n|   21   | Combivent   |     Janet | 2018-12-08 3:00:00 PM  |\n|  100   | Dilantin    |   Melanie | 2020-09-14 4:44:44 PM  |\n+--------+-------------+-----------+------------------------+\n```\n\n### Controlling column widths\n\nThe library automatically sizes column widths based on the maximum width of any individual row. However the user can override this if it happens that the data may be too wide to display in a readable format. In such cases we can explicitly set the column widths:\n\n\n```csharp\ntable.Columns[1].SetWidth(8);\ntable.Columns[3].SetWidth(33);\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+---------------------------------------------------------------+\n|                         Prescriptions                         |\n+--------+--------+-----------+---------------------------------+\n| Dosage |  Drug  |  Patient  |              Date               |\n+--------+--------+-----------+---------------------------------+\n| 25     | Indo.. | David     | 2008-05-01 12:30:52 PM          |\n| 50     | Eneb.. | Sam       | 2008-09-11 8:42:30 AM           |\n| 10     | Hydr.. | Christoff | 2019-12-12 9:15:00 AM           |\n| 21     | Comb.. | Janet     | 2018-12-08 3:00:00 PM           |\n| 100    | Dila.. | Melanie   | 2020-09-14 4:44:44 PM           |\n+--------+--------+-----------+---------------------------------+\n```\n\nNote that ellipses (`..`) are added if the string cannot be contained within the width requested.\n\n### Custom formatting\n\nBy default the library calls the `ToString` API to convert the row objects into strings, however sometimes we require custom printing. The library supports arbitrary control of the string to be printed via a method callback which the user supplies. In this example we want to put an asterisk next to a dosage which exceeds 23 units. We can do this as follows:\n\n```csharp\ntable.Columns[0].SetDataTextFormat((DataColumn c, DataRow r) =\u003e\n{\n    Int32 value = r.Field\u003cInt32\u003e(c);\n\n    return value \u003e 23 ? $\"{value} (*)\" : $\"{value}\";\n});\n\nConsole.WriteLine(table.ToPrettyPrintedString());\n```\n\nOutput:\n\n```\n+------------------------------------------------------------+\n|                       Prescriptions                        |\n+---------+-------------+-----------+------------------------+\n| Dosage  |    Drug     |  Patient  |          Date          |\n+---------+-------------+-----------+------------------------+\n| 25 (*)  | Indocin     | David     | 2008-05-01 12:30:52 PM |\n| 50 (*)  | Enebrel     | Sam       | 2008-09-11 8:42:30 AM  |\n| 10      | Hydralazine | Christoff | 2019-12-12 9:15:00 AM  |\n| 21      | Combivent   | Janet     | 2018-12-08 3:00:00 PM  |\n| 100 (*) | Dilantin    | Melanie   | 2020-09-14 4:44:44 PM  |\n+---------+-------------+-----------+------------------------+\n```\n\n## Tests\n\nA set of unit tests covers all features of the library by comparing the result against a hand verified output. To run the tests simply:\n\n```shell\ndotnet build\ndotnet test\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjeremic%2Fdatatableprettyprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffjeremic%2Fdatatableprettyprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjeremic%2Fdatatableprettyprinter/lists"}