ColumnDataTypeCollection.Item[Int32] Property
Gets or sets the data type of a specific column in the imported text document.
Namespace: DevExpress.XtraSpreadsheet.Import
Assembly: DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
#Declaration
public ColumnDataType this[int columnIndex] { get; set; }
#Parameters
Name | Type | Description |
---|---|---|
column |
Int32 | A zero-based index of the column in the imported document whose data type should be set or obtained. |
#Property Value
Type | Description |
---|---|
Column |
A Column |
Available values:
Name | Description |
---|---|
General | Specifies that the type of column values should be recognized automatically based on the column content (numeric values will be converted to numbers, date values to dates, etc.). |
Numeric | Specifies that column values should be interpreted as numbers. If conversion fails, column values are treated as strings. |
Date |
Specifies that column values should be interpreted as date and time values. If conversion fails, column values are treated as strings. |
Boolean | Specifies that column values should be interpreted as boolean values. If conversion fails, column values are treated as strings. |
Error | Specifies that column values should be interpreted as errors. If conversion fails, column values are treated as strings. |
Text | Specifies that column values should be interpreted as text and corresponding cells will be formatted as text, so that anything you type into these cells will be treated as text including numbers. |
#Remarks
The following example demonstrates how to use the Item property of the ColumnDataTypeCollection collection (accessible from the CsvDocumentImporterOptions.ColumnTypes property) to specify a data type of the first column in a CSV document being loaded into the SpreadsheetControl.
private void SpreadsheetControl_BeforeImport(object sender, SpreadsheetBeforeImportEventArgs e)
{
if (e.DocumentFormat == DocumentFormat.Csv)
{
DevExpress.XtraSpreadsheet.Import.CsvDocumentImporterOptions options = (DevExpress.XtraSpreadsheet.Import.CsvDocumentImporterOptions)e.Options;
// Specify the data format for the first column in the imported document.
options.ColumnTypes[0] = DevExpress.XtraSpreadsheet.Import.ColumnDataType.Text;
}
}