DevExpress.DataAccess.Excel.ExcelDataSource myExcelSource = new DevExpress.DataAccess.Excel.ExcelDataSource();[VB]
Dim myExcelSource As New DevExpress.DataAccess.Excel.ExcelDataSource()2. 使用ExcelDataSource.FileName或ExcelDataSource.Stream属性为组件提供来自本地存储或流的数据源。 [C#]
myExcelSource.FileName = @"d:\Work\Excel DataSources\Book1.xlsx";[VB]
myExcelSource.FileName = "d:\Work\Excel DataSources\Book1.xlsx"3. 根据数据源类型(Excel工作簿或CSV文件),创建一个ExcelSourceOptions或CsvSourceOptions对象。使用此对象的属性,可以指定要加载的单元格范围。将创建的对象分配给ExcelDataSource.SourceOptions属性。 [C#]
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("SalesPerson", "A1:L100"); myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings); //or myExcelSource.SourceOptions = new CsvSourceOptions() { CellRange = "A1:L100" };[VB]
Dim worksheetSettings As New ExcelWorksheetSettings("SalesPerson", "A1:L100") myExcelSource.SourceOptions = New ExcelSourceOptions(worksheetSettings) 'or myExcelSource.SourceOptions = New CsvSourceOptions() With {.CellRange = "A1:L100"}4. 如果需要,请设置其他导入选项 [C#]
myExcelSource.SourceOptions.SkipEmptyRows = false; myExcelSource.SourceOptions.UseFirstRowAsHeader = true;[VB]
myExcelSource.SourceOptions.SkipEmptyRows = False myExcelSource.SourceOptions.UseFirstRowAsHeader = True5. 将您的ExcelDataSource分配给数据感知控件,并调用组件的Fill方法以用记录填充它。 [C#]
myExcelSource.Fill(); gridControl1.DataSource = myExcelSource;[VB]
myExcelSource.Fill() gridControl1.DataSource = myExcelSource完整的代码如下所示。 [C#]
using DevExpress.DataAccess.Excel; //. . . DevExpress.DataAccess.Excel.ExcelDataSource myExcelSource = new DevExpress.DataAccess.Excel.ExcelDataSource(); myExcelSource.FileName = @"d:\Work\Excel DataSources\Book1.xlsx"; ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("SalesPerson", "A1:L13"); myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings); //or myExcelSource.SourceOptions = new CsvSourceOptions() { CellRange = "A1:L100" }; myExcelSource.SourceOptions.SkipEmptyRows = false; myExcelSource.SourceOptions.UseFirstRowAsHeader = true; gridControl1.DataSource = myExcelSource; myExcelSource.Fill();[VB]
Imports DevExpress.DataAccess.Excel '. . . Dim myExcelSource As New DevExpress.DataAccess.Excel.ExcelDataSource() myExcelSource.FileName = "d:\Work\Excel DataSources\Book1.xlsx" Dim worksheetSettings As New ExcelWorksheetSettings("SalesPerson", "A1:L13") myExcelSource.SourceOptions = New ExcelSourceOptions(worksheetSettings) 'or myExcelSource.SourceOptions = New CsvSourceOptions() With {.CellRange = "A1:L100"} myExcelSource.SourceOptions.SkipEmptyRows = False myExcelSource.SourceOptions.UseFirstRowAsHeader = True gridControl1.DataSource = myExcelSource myExcelSource.Fill()
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/901.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/901.html