Is it possible to mimic the "Format as Table" Excel function in C#?

Viewed 28

Just wondering if there's a way to mimic the "Format as Table" Excel function in C# for .csv files.

Context:

The WPF .NET Framework program I've created generates a 8x19 or 7x19 grid of data. The data collected is always different. My program can export this data into a CSV file. This is what it looks like when exported: enter image description here

My customer is wanting the data in the CSV file to already be formatted into a table like so: enter image description here

Is there a way to format it as a table after the data has been exported (besides manually doing it in Excel)?

1 Answers

Look into ClosedXML. Here is the documentation for your use case It's published under MIT license.

Something like this should do the trick:

var wb = new XLWorkbook(); 
var ws = wb.AddWorksheet("Sheet1"); 
var range = ws.Range(1, 1, 50, 5); 
var table = range.CreateTable();
table.Theme = XLTableTheme.TableStyleLight12;
Related