C# Interop Excel format like Excel's format as table

Horbert picture Horbert · Feb 6, 2013 · Viewed 10.5k times · Source

I'm exporting a table from SQLite to Excel (2010) in C#. It works fine. I'm using the Excel.Range.set_Value() method.

How can I format an Excel.Range like Excel's format (like a table) would?

Answer

David Yenglin picture David Yenglin · Feb 6, 2013

To expand upon my comment and add to D Stanley.

Range range = ws.get_Range("A1:D5");
wrksheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, range, missing, Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, missing).Name = "MyTableStyle";
wrksheet.ListObjects.get_Item("MyTableStyle").TableStyle = "TableStyleMedium1";