Import Settings
- PreferredDateTimeFormat: This property gets or sets the default format string when importing DateTime columns.
- ShouldImportColumnHeaders: Controls whether the column headers should be imported.
- StartCellIndex: Get or sets the index where the table should start in the Worksheet.
The CellImported event
The CellImported event is fired for each cell and allows you to change the cell properties.
The CellImportedEventArgs contains information about the current cell:
- dataTableRowIndex: The index of the row in the DataTable containing the cell that the event occurs for.
- dataTableColumnIndex: The index of the column in the DataTable containing the cell that the event occurs for.
- worksheetRowIndex: The index of the row in the Worksheet containing the cell that the event occurs for.
- worksheetColumnIndex: The index of the column in the Worksheet containing the cell that the event occurs for.
- worksheet: The worksheet where the data is imported.
Example 1: Using the CellImported event to format the cells
private void ImportTable()
{
DataTable table = GetTable();
DataTableFormatProvider provider = new DataTableFormatProvider();
provider.ImportSettings.CellImported += ImportSettings_CellImported;
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets.Add();
provider.Import(table, worksheet);
this.radSpreadsheet.Workbook = workbook;
}
private void ImportSettings_CellImported(object sender, CellImportedEventArgs e)
{
if (e.DataTableColumnIndex == 1 && e.WorksheetRowIndex > 1)
{
e.Worksheet.Cells[e.WorksheetRowIndex, e.WorksheetColumnIndex].SetForeColor(new ThemableColor(Colors.Red));
}
}
Export Settings
- HasHeaderRow: Gets or sets whether the header row of the worksheet should be exported.
- ShouldSetDataTypes: Gets or sets whether the exporter should try to parse the data types from the spreadsheet. If false only objects will be exported.
- DataTableCulture: Get or sets the DataTable culture. By default the culture of the workbook is used.
- RangeToExport: Get or sets the cell range for which the data will be exported.
The ColumnExporting event
The ColumnExporting event is fired for each column before the column is added to the table and allows you to change its properties.
The ColumnExportingEventArgs object contains the the current column instance and its index:
- DataColumn: Gets the DataColumn that is being exported.
- ColumnIndex: Gets the index of the exported column.
Example 2: Using the ColumnExporting event to set the AllowDBNull property
private void ExportTable()
{
DataTableFormatProvider provider = new DataTableFormatProvider();
provider.ExportSettings.ColumnExporting += this.ExportSettings_ColumnExporting;
var table = provider.Export(radSpreadsheet.Workbook.ActiveWorksheet);
}
private void ExportSettings_ColumnExporting(object sender, ColumnExportingEventArgs e)
{
if (e.ColumnIndex == 3)
{
e.DataColumn.AllowDBNull = true;
}
}