Set style on AddTable

My application creates an Excel file from scratch.
Once the file has been filled in, I would like to format the data in the form of an Excel table with the following formats:

  • First line in bold
  • Presence of a filter for each column
  • Alternating grey and white lines in the table

Here is the code I use to perform this operation:

p_xfData.AddTable(new TTableDefinition()
{
  Name = "Poles",
  HasAutofilter = true,
  HasHeaderRow = true,
  Style = new TTableStyle("PolesTableStyle", false, true, false, true),
  Range = new TXlsCellRange(1, 1, p_xfData.RowCount, p_xfData.ColCount)
});

Please tell me how I can make the rows alternate between grey and white. The defined style doesn't seem to work.

Thank you in advance for your support.

Hi,
The problem is that you are using a "PolesTableStyle", which is an unknown table style, so it doesn't have a format applied, and while it is the alternating styles for the rows (the last parameter in the Style definition), it alternates between 2 empty styles.

Try doing something like:

new TTableStyle("TableStyleMedium2", false, true, false, true);

And as usual, to know the existing tablestyle names (or even to create your own), the best thing is to use APIMate (what I did to write the example above). Create your table in Excel, choose the table format you want, then open the file in APIMate and look at the code for that table.

You can either choose a table style from here:

Or create a new one by selecting the "Net table Style" at the bottom. APIMate should show you how to do both.

Thank you very much for the very accurate support.

In future, I'll be using APIMate, which really saves time

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.