TextTable: Fast, Easy Tabular Text

TextTable is a C# class that makes it easy to define tabular data formats and render them in fixed-width text. It started out as the answer to an email reporting requirement, and evolved into something fairly flexible. Here’s a screenshot of the output from the example program included in the archive, in which several TextTables are used to create an invoice.

ttscreen

The text that TextTable produces looks correct when viewed with fixed-width fonts such as System, and the default font used by the console window. I have some ideas in mind for extending it to work with proportional fonts as well. In the meantime you might find it useful for creating email bodies, dumping tabular data to a text file, or logging.

TextTable works similarly to a DataTable, in that you define columns and their properties, and add rows. Calling a TextTable’s Render() method outputs the formatted text to a string, or to a StreamWriter. Alternatively you can render the individual rows progressively. Columns support multiline with wrapping, horizontal alignment, and custom formatting strings. There are several options for defining and rendering headers, and how they behave.

There is no documentation at this time, but the source is pretty well commented and the example program shows a good selection of the things you can do with it. Dumping tabular text to a file or to the screen isn’t a high-tech undertaking, but when you need it, you need it. I hope that if you need it you will find TextTable useful.

TextTools (TextTable) Assembly, Source, and Project Files

Leave a Reply

Your email address will not be published. Required fields are marked *