SpreadsheetGear
CopyFromDataTable Method
See Also  Send Feedback
SpreadsheetGear Namespace > IRange Interface : CopyFromDataTable Method

dataTable
Specifies the source DataTable.
flags
Specifies options including All Text values, No Column Headers and Insert Cells.
Copies the specified DataTable to this range.

Syntax

Visual Basic (Declaration) 
Sub CopyFromDataTable( _
   ByVal dataTable As DataTable, _
   ByVal flags As SetDataFlags _
) 
C# 
void CopyFromDataTable( 
   DataTable dataTable,
   SetDataFlags flags
)

Parameters

dataTable
Specifies the source DataTable.
flags
Specifies options including All Text values, No Column Headers and Insert Cells.

Example

See DataSet to Excel Workbook with Formats and Formulas in the Excel Reporting Samples and DataTable to Excel Workbook with Formats and Formulas in the Excel to DataGrid Samples for examples of using CopyFromDataTable.

Remarks

If this range is a single column, the destination range will be expanded to the number of columns in the DataTable.

If this range is a single row, the destination will be expanded to the number of rows in the DataTable, plus one row for the column headers if needed.

Note that you must specify a single data row and allow the destination size to be determined automatically if you use SetDataFlags.WrapToNewWorksheet to enable wrapping rows to the next worksheet if they do not fit on the current worksheet.

Using Formats and Formulas
To preformat a range and have formulas refer to columns in the range, specify the SpreadsheetGear.Data.SetDataFlags.InsertCells flag. When specifying this flag, you must provide a range with exactly two rows for data, preceded by a row for column headers if SpreadsheetGear.Data.SetDataFlags.NoColumnNames is not specified.

Specifying this flag instructs SpreadsheetGear to insert or delete rows as needed to accommodate the number of rows in the source DataTable, and to copy down values or formulas in extra columns which enables "calculated columns". This allows the cells to be preformatted and allows formulas to reference cells within the destination range. If the DataTable contains no rows, both data rows will be deleted and any formula references to these cells will be changed to #REF!. Otherwise, formulas referring to cells in the second initial row will be fixed up to refer to the last row of data inserted into the worksheet.

DataTable Column Names to Range Column Headers
By default, column names are copied to the first row in the specified range. To disable this functionality, specify SpreadsheetGear.Data.DataSet.NoColumnHeaders.

Forcing Some or All Values to Text
Normally, an attempt is made to parse values as they are placed into cells. To force all values to be entered into cells as text, specify the SpreadsheetGear.Data.SetDataFlags.AllText flag. To force only specific columns to be placed into cells as text, use the SpreadsheetGear.Data.SetDataFlags.InsertCells flag which enables you to preformat these columns as text cells (IRange.NumberFormat = "@").

Requirements

Platforms: x86 and x64 versions of Windows 2000, Windows XP, Windows Vista, Windows 7, Windows Server 2003 (including R2) and Windows Server 2008 (including R2). SpreadsheetGear 2009 requires the Microsoft .NET Framework 2.0 and supports .NET 3.0 and .NET 3.5.

See Also

Copyright © 2003-2009 SpreadsheetGear LLC. All Rights Reserved.Help Powered by Innovasys   
SpreadsheetGear is a registered trademark of SpreadsheetGear LLC.
Microsoft, Microsoft Excel and Visual Studio are trademarks or registered trademarks of Microsoft Corporation.