Version

FormatAsTable(Boolean,WorksheetTableStyle) Method

Formats the region as a table and adds an associated WorksheetTable to the Worksheet.Tables collection.
Syntax
'Declaration
 
Public Overloads Function FormatAsTable( _
   ByVal tableHasHeaders As Boolean, _
   ByVal tableStyle As WorksheetTableStyle _
) As WorksheetTable
public WorksheetTable FormatAsTable( 
   bool tableHasHeaders,
   WorksheetTableStyle tableStyle
)

Parameters

tableHasHeaders
A value which indicates whether the top row of the region contains the headers for the table.
tableStyle
The WorksheetTableStyle to apply to the table or null to use the Workbook.DefaultTableStyle.

Return Value

The WorksheetTable created the represent the formatted table for the region.
Exceptions
ExceptionDescription
System.ArgumentExceptionThe specified tableStyle does not exist in the CustomTableStyles or StandardTableStyles collections.
System.InvalidOperationExceptionThe region contains one or more cells from another WorksheetTable.
System.InvalidOperationExceptionThe region contains one or more cells which have a multi-cell ArrayFormula applied.
System.InvalidOperationExceptionThe region contains one or more cells which are part of a WorksheetDataTable.
Remarks

When the table is created, the specified tableStyle will be applied to the value.

When the table is created, the column names will be taken from the cells in the header row if tableHasHeaders is True. If it is False, the column names will be generated and the cells for the header row will be inserted into the worksheet.

The column names are unique within the owning WorksheetTable. If, when the table is created, there are two or more columns with the same name, the second and subsequent duplicate column names will have a number appended to make them unique. If any cells in the header row have a non-string value, their value will be changed to a string (the current display text of the cell). If any cells in the header row have no value, they will be given a generated column name.

If the region partially contains any merged cell regions, they will be removed from the worksheet and the table region will be expanded to include all cells from the merged region.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also