Data Management (ImportSettings/Schema)

Profile Reply
gabossolo Client

Hi -- Could please help me the how to create an import Schema for ExcelDataSource?


User Description Posted On
MariyaVoytovich Agent

Hello gabossolo!

The code below shows an example of importing data from Excel.
For the example, the Shipper object was used from the demo Northwind.

public void ImportShippersFromExcel()
// Arrange
var shipperType = typeof(Shipper);
ITypeInfo shipperTypeInfo = XafTypesInfo.CastTypeToTypeInfo(shipperType);

ISettings settings = new ImportSettings();

ISchema schema = new Schema();

const string tableName = "Shippers";
ITypeMap shipperTypeMap = new TypeMap(shipperTypeInfo.FullName, tableName);

shipperTypeMap.KeyMemberName = "Oid";
shipperTypeMap.KeyMemberType = shipperTypeInfo.FindMember("Oid").MemberType.FullName;
shipperTypeMap.KeyColumnName = "ShipperID";
shipperTypeMap.KeyColumnType = "System.Int32";

shipperTypeMap.MemberMapping.Add(new MemberMap(shipperTypeInfo.FindMember("Name").Name, "CompanyName"));
shipperTypeMap.MemberMapping.Add(new MemberMap(shipperTypeInfo.FindMember("Phone").Name, "Phone"));

settings.Schema = schema;

const string sourcePath = "Northwind.xls";
IDataSource dataSource = new ExcelDataSource(sourcePath);
dataSource.Schema = settings.Schema;

IOperation operation = new ImportOperation(Application);
operation.DataSource = dataSource;
operation.Settings = settings;

// Act


Feel free to contact us if you need further assistance or have additional questions.

On behalf of Xafari Client Services Team

× This ticket is closed.

Write US