DestField: Integer;
DestField: integer;
The DestField property returns the number of the field in the data consumer.
To get the number of the corresponding field in the data source, use the ICubeMetaLoaderLogEntry.SourceField property.
Executing the example requires that the repository contains a time series database with the TSDB_UNPIVOT identifier containing time series attributes with the COUNTRY and INDICATOR identifiers. The COUNTRY attribute must be a link to MDM dictionary, and the INDICATOR attribute must be a link to MDM table dictionary.
The file system must contain the file D:\Indicator_Data.xlsx containing a data sheet named Sheet1.
Add links to the Cubes, Db, Dimensions, Dt, Metabase, Rds system assemblies.
The contents of the Sheet1 sheet in the file D:\Indicator_Data.xlsx
<font color="#008080">Sub</font><font color="#000000"> UserProc;<br /> </font><font color="#008080">Var</font><font color="#000000"><br /> mb: IMetabase;<br /> desc: IMetabaseObjectDescriptor;<br /> importObject: IImportRequestDefinition;<br /> createInfo: IMetabaseObjectCreateInfo;<br /> params: IImportRequestProviderParams;<br /> importBinding: ICubeMetaLoaderBinding;<br /> Bindings: ICubeMetaLoaderBindings;<br /> rdsDictionary: IRdsDictionary;<br /> excel: IDtExcelProviderEx;<br /> instance: IImportRequestInstance;<br /> importResult: IImportRequestResult;<br /> Log: ICubeMetaLoaderLog;<br /> LogStr: String;<br /> count, i: Integer;<br /> entry: ICubeMetaLoaderLogEntry;<br /> rub: IRubricator;<br /> Unpivot: IDtUnpivotProvider;<br /> Attributes: IMetaAttributes;<br /> </font><font color="#008080">Begin</font><font color="#000000"><br /> MB := MetabaseClass.Active;<br /> </font><font color="#008000">// Get and clear time series database<br /> </font><font color="#000000"> desc := mb.ItemById(</font><font color="#800000">"TSDB_UNPIVOT"</font><font color="#000000">);<br /> rub := desc.Bind </font><font color="#008080">As</font><font color="#000000"> IRubricator;<br /> rub.Truncate;<br /> </font><font color="#008000">// Create an object to import time series<br /> </font><font color="#000000"> createInfo := mb.CreateCreateInfo;<br /> createInfo.ClassId := MetabaseObjectClass.KE_CLASS_IMPORTREQUEST;<br /> </font><font color="#008000">// Set object parameters<br /> </font><font color="#000000"> createInfo.Name := </font><font color="#800000">"Import from file"</font><font color="#000000">;<br /> createInfo.KeepEdit := </font><font color="#008080">True</font><font color="#000000">;<br /> createInfo.Permanent := </font><font color="#008080">False</font><font color="#000000">;<br /> createInfo.Parent := desc;<br /> importObject := mb.CreateObject(createInfo) </font><font color="#008080">As</font><font color="#000000"> IImportRequestDefinition;<br /> </font><font color="#008000">// Set source type from which data will be imported<br /> </font><font color="#000000"> importObject.SourceType := ImportRequestSourceType.Provider;<br /> </font><font color="#008000">// Set time series databse to which data will be imported<br /> </font><font color="#000000"> importObject.DestinationRubricator := desc.Bind </font><font color="#008080">As</font><font color="#000000"> IRubricator;<br /> </font><font color="#008000">// Set import parameters<br /> </font><font color="#000000"> params := importObject.ProviderParams;<br /> </font><font color="#008000">// Deselect constraint to maximum number of errors in report about data import<br /> </font><font color="#000000"> (params </font><font color="#008080">As</font><font color="#000000"> ICubeMetaLoader).Log.MaxErrors := -</font><font color="#008000">1</font><font color="#000000">;<br /> </font><font color="#008000">// Get attribute bindings<br /> </font><font color="#000000"> Bindings := params.Bindings;<br /> </font><font color="#008000">// Get time series attributes;<br /> </font><font color="#000000"> Attributes := rub.Facts.Attributes;<br /> </font><font color="#008000">// Get dictionary to which the COUNTRY attribute is referenced<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"COUNTRY"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create binding for the COUNTRY attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add;<br /> importBinding.BindingType := CubeMetaLoaderBindingType.Attribute;<br /> importBinding.Attribute := </font><font color="#800000">"COUNTRY"</font><font color="#000000">;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item(</font><font color="#008000">0</font><font color="#000000">).Id;<br /> </font><font color="#008000">// Determine that data for attribute will be taken by filed number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.Index;<br /> </font><font color="#008000">// Determine filed number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"0"</font><font color="#000000">;<br /> </font><font color="#008000">// Get dictionary to which references the INDICATOR attribute<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"INDICATOR"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create binding for the INDICATOR attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add;<br /> importBinding.BindingType := CubeMetaLoaderBindingType.Attribute;<br /> importBinding.Attribute := </font><font color="#800000">"INDICATOR"</font><font color="#000000">;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item(</font><font color="#008000">1</font><font color="#000000">).Id;<br /> </font><font color="#008000">// Determine that data for the attribute will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.Index;<br /> </font><font color="#008000">// Determine field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"1"</font><font color="#000000">;<br /> </font><font color="#008000">// Get dictionary to which references the UNIT attribute<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"UNIT"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create binding for the UNIT attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add;<br /> importBinding.BindingType := CubeMetaLoaderBindingType.Unit;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item(</font><font color="#008000">0</font><font color="#000000">).Id;<br /> </font><font color="#008000">// Determine that specified value will be taken as attribute data<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.ConstValue;<br /> </font><font color="#008000">// Set attribute value<br /> </font><font color="#000000"> importBinding.FieldValue := </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">As</font><font color="#000000"> Variant;<br /> </font><font color="#008000">// Create binding for calendar<br /> </font><font color="#000000"> importBinding := Bindings.Add;<br /> importBinding.BindingType := CubeMetaLoaderBindingType.Calendar;<br /> importBinding.ByColumns := </font><font color="#008080">False</font><font color="#000000">;<br /> importBinding.CalendarDateFormatEx(DimCalendarLevel.Year) := </font><font color="#800000">"$Year$"</font><font color="#000000">;<br /> importBinding.CalendarOptions.Levels := DimCalendarLevelSet.Year;<br /> </font><font color="#008000">// Determine that data for calendar will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.Index;<br /> </font><font color="#008000">// Determine field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"2"</font><font color="#000000">;<br /> </font><font color="#008000">// Create binding for time series variables<br /> </font><font color="#000000"> importBinding := Bindings.Add;<br /> importBinding.BindingType := CubeMetaLoaderBindingType.Value;<br /> </font><font color="#008000">// Determine that values will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.Index;<br /> </font><font color="#008000">// Determine field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"3"</font><font color="#000000">;<br /> </font><font color="#008000">// Set data source<br /> </font><font color="#000000"> </font><font color="#008080">Try</font><font color="#000000"><br /> excel := </font><font color="#008080">New</font><font color="#000000"> DtExcelProviderEx.Create;<br /> </font><font color="#008000">// Set parameters of the file from which data will be imported<br /> </font><font color="#000000"> excel.File := </font><font color="#800000">"D:\Indicator_Data.xlsx"</font><font color="#000000">;<br /> excel.Sheet := </font><font color="#800000">"Лист1"</font><font color="#000000">;<br /> excel.Format := </font><font color="#800000">"XLSX"</font><font color="#000000">;<br /> Excel.HasHeader := </font><font color="#008080">False</font><font color="#000000">;<br /> </font><font color="#008000">// Set data area location in source file<br /> </font><font color="#000000"> Unpivot := </font><font color="#008080">New</font><font color="#000000"> DtUnpivotProvider.Create;<br /> Unpivot.Provider := Excel;<br /> Unpivot.LeftEnd := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataWidth := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataTop := </font><font color="#008000">3</font><font color="#000000">;<br /> Unpivot.DataBottom := </font><font color="#008000">5</font><font color="#000000">;<br /> Unpivot.HeadBottom := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataRight := </font><font color="#008000">8</font><font color="#000000">;<br /> Unpivot.HeadColumn := </font><font color="#008000">1</font><font color="#000000">;<br /> Unpivot.LeftBegin := </font><font color="#008000">1</font><font color="#000000">;<br /> Unpivot.HeadTop := </font><font color="#008000">2</font><font color="#000000">;<br /> </font><font color="#008000">// Load data<br /> </font><font color="#000000"> Unpivot.Open;<br /> count := Unpivot.Fields.Count;<br /> importObject.ProviderParams.Provider := Unpivot </font><font color="#008080">As</font><font color="#000000"> IDatasetDataProvider;<br /> instance := (importObject </font><font color="#008080">As</font><font color="#000000"> IMetabaseObject).Open(</font><font color="#008080">Null</font><font color="#000000">) </font><font color="#008080">As</font><font color="#000000"> IImportRequestInstance;<br /> Instance.LoadData;<br /> </font><font color="#008000">// Get report about data loading<br /> </font><font color="#000000"> importResult := instance.ImportResult;<br /> Log := importResult.Log;<br /> count := Log.Count;<br /> </font><font color="#008000">// Display report to console window<br /> </font><font color="#000000"> Debug.WriteLine(</font><font color="#800000">"Number of records = "</font><font color="#000000"> + Count.ToString);<br /> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br /> Entry := Log.Item(i);<br /> LogStr := i.ToString + </font><font color="#800000">": "</font><font color="#000000"><br /> + (Entry.IsError ? </font><font color="#800000">"Ошибка: "</font><font color="#000000"> :(Entry.IsMessage ? </font><font color="#800000">"Сообщение: "</font><font color="#000000"> : </font><font color="#800000">"Warning: "</font><font color="#000000">)) +<br /> + Entry.ErrorMessage;<br /> Debug.WriteLine(LogStr);<br /> Debug.Indent;<br /> Debug.WriteLine(</font><font color="#800000">"Record number = "</font><font color="#000000"> + Entry.RecordNumber.ToString);<br /> Debug.WriteLine(</font><font color="#800000">"Record value = "</font><font color="#000000"> + Entry.ValueRecordNumber.ToString);<br /> Debug.WriteLine(</font><font color="#800000">"Field in data source = "</font><font color="#000000"> + Entry.Field);<br /> Debug.WriteLine(</font><font color="#800000">"Number of record in data source = "</font><font color="#000000"> + Entry.SourceRecord.ToString);<br /> Debug.WriteLine(</font><font color="#800000">"Number of field in data source = "</font><font color="#000000"> + Entry.SourceField.ToString);<br /> Debug.WriteLine(</font><font color="#800000">"Number of record in data consumer = "</font><font color="#000000"> + Entry.DestRecord.ToString);<br /> Debug.WriteLine(</font><font color="#800000">"Number of field in data consumer = "</font><font color="#000000"> + Entry.DestField.ToString);<br /> Debug.Unindent;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br /> </font><font color="#008080">Except</font><font color="#000000"> </font><font color="#008080">On</font><font color="#000000"> e: Exception </font><font color="#008080">Do</font><font color="#000000"><br /> Debug.WriteLine(e.Message);<br /> </font><font color="#008080">Finally</font><font color="#000000"><br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Try</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> UserProc;</font>
After executing the example data is imported from the file D:\Indicator_Data.xlsx into the TSDB_UNPIVOT time series database. Import errors are displayed in the console window.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Rds;
<font color="#008080">Public</font><font color="#000000"> </font><font color="#008080">Shared</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> Main(Params: StartParams);<br /> </font><font color="#008080">Var</font><font color="#000000"><br /> mb: IMetabase;<br /> desc: IMetabaseObjectDescriptor;<br /> importObject: IImportRequestDefinition;<br /> createInfo: IMetabaseObjectCreateInfo;<br /> ImportParams: IImportRequestProviderParams;<br /> importBinding: ICubeMetaLoaderBinding;<br /> Bindings: ICubeMetaLoaderBindings;<br /> rdsDictionary: IRdsDictionary;<br /> excel: IDtExcelProviderEx;<br /> instance: IImportRequestInstance;<br /> importResult: IImportRequestResult;<br /> Log: ICubeMetaLoaderLog;<br /> LogStr: String;<br /> count, i: Integer;<br /> entry: ICubeMetaLoaderLogEntry;<br /> rub: IRubricator;<br /> Unpivot: IDtUnpivotProvider;<br /> Attributes: IMetaAttributes;<br /> </font><font color="#008080">Begin</font><font color="#000000"><br /> MB := Params.Metabase;<br /> </font><font color="#008000">// Get and clear time series database<br /> </font><font color="#000000"> desc := mb.ItemById[</font><font color="#800000">"TSDB_UNPIVOT"</font><font color="#000000">];<br /> rub := desc.Bind() </font><font color="#008080">As</font><font color="#000000"> IRubricator;<br /> rub.Truncate();<br /> </font><font color="#008000">// Create an object to import time series database<br /> </font><font color="#000000"> createInfo := mb.CreateCreateInfo();<br /> createInfo.ClassId := MetabaseObjectClass.KE_CLASS_IMPORTREQUEST </font><font color="#008080">As</font><font color="#000000"> integer;<br /> </font><font color="#008000">// Set object parameters<br /> </font><font color="#000000"> createInfo.Name := </font><font color="#800000">"Import from file"</font><font color="#000000">;<br /> createInfo.KeepEdit := </font><font color="#008080">True</font><font color="#000000">;<br /> createInfo.Permanent := </font><font color="#008080">False</font><font color="#000000">;<br /> createInfo.Parent := desc;<br /> importObject := mb.CreateObject(createInfo) </font><font color="#008080">As</font><font color="#000000"> IImportRequestDefinition;<br /> </font><font color="#008000">// Set source type from which data will be imported<br /> </font><font color="#000000"> importObject.SourceType := ImportRequestSourceType.irstProvider;<br /> </font><font color="#008000">// Set time series database where data will be imported<br /> </font><font color="#000000"> importObject.DestinationRubricator := desc.Bind() </font><font color="#008080">As</font><font color="#000000"> IRubricator;<br /> </font><font color="#008000">// Set import parameters<br /> </font><font color="#000000"> ImportParams := importObject.ProviderParams;<br /> </font><font color="#008000">// Remove a restriction to get a maximum number of errors in data import report<br /> </font><font color="#000000"> (ImportParams </font><font color="#008080">As</font><font color="#000000"> ICubeMetaLoader).Log.MaxErrors := -</font><font color="#008000">1</font><font color="#000000">;<br /> </font><font color="#008000">// Get attribute bindings<br /> </font><font color="#000000"> Bindings := ImportParams.Bindings;<br /> </font><font color="#008000">// Get time series attributes;<br /> </font><font color="#000000"> Attributes := rub.Facts.Attributes;<br /> </font><font color="#008000">// Get dictionary to which refers the COUNTRY attribute<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"COUNTRY"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind() </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create a binding for the COUNTRY attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add();<br /> importBinding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;<br /> importBinding.Attribute := </font><font color="#800000">"COUNTRY"</font><font color="#000000">;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item[</font><font color="#008000">0</font><font color="#000000">].Id;<br /> </font><font color="#008000">// Specify that data for attribute will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;<br /> </font><font color="#008000">// Specify field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"0"</font><font color="#000000">;<br /> </font><font color="#008000">// Get dictionary to which refers the INDICATOR attribute<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"INDICATOR"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind() </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create a binding for the INDICATOR attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add();<br /> importBinding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;<br /> importBinding.Attribute := </font><font color="#800000">"INDICATOR"</font><font color="#000000">;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item[</font><font color="#008000">1</font><font color="#000000">].Id;<br /> </font><font color="#008000">// Specify that data for attribute will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;<br /> </font><font color="#008000">// Specify field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"1"</font><font color="#000000">;<br /> </font><font color="#008000">// Get dictionary to which the UNIT attribute refers<br /> </font><font color="#000000"> desc := Attributes.FindById(</font><font color="#800000">"UNIT"</font><font color="#000000">).ValuesObject;<br /> rdsDictionary := desc.Bind() </font><font color="#008080">As</font><font color="#000000"> IRdsDictionary;<br /> </font><font color="#008000">// Create a binding for the UNIT attribute<br /> </font><font color="#000000"> importBinding := Bindings.Add();<br /> importBinding.BindingType := CubeMetaLoaderBindingType.cmlbtUnit;<br /> importBinding.Dimension := rdsDictionary </font><font color="#008080">As</font><font color="#000000"> IDimensionModel;<br /> importBinding.KeyAttribute := rdsDictionary.Attributes.Key.Id;<br /> importBinding.Index := rdsDictionary.UniqueKeys.Item[</font><font color="#008000">0</font><font color="#000000">].Id;<br /> </font><font color="#008000">// Specify that the specifed value will be taken as attribute value<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.cmlftConstValue;<br /> </font><font color="#008000">// Set attribute value<br /> </font><font color="#000000"> importBinding.FieldValue := </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">As</font><font color="#000000"> object;<br /> </font><font color="#008000">// Create a binding for calendar<br /> </font><font color="#000000"> importBinding := Bindings.Add();<br /> importBinding.BindingType := CubeMetaLoaderBindingType.cmlbtCalendar;<br /> importBinding.ByColumns := </font><font color="#008080">False</font><font color="#000000">;<br /> importBinding.CalendarDateFormatEx[DimCalendarLevel.dclYear] := </font><font color="#800000">"$Year$"</font><font color="#000000">;<br /> importBinding.CalendarOptions.Levels := DimCalendarLevelSet.dclsYear;<br /> </font><font color="#008000">// Specify that data for calendar will be taken by field number in data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;<br /> </font><font color="#008000">// Set field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"2"</font><font color="#000000">;<br /> </font><font color="#008000">// Create a binding for time series values<br /> </font><font color="#000000"> importBinding := Bindings.Add();<br /> importBinding.BindingType := CubeMetaLoaderBindingType.cmlbtValue;<br /> </font><font color="#008000">// Soecify that values will be taken by field number in&data source<br /> </font><font color="#000000"> importBinding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;<br /> </font><font color="#008000">// Specify field number<br /> </font><font color="#000000"> importBinding.Field := </font><font color="#800000">"3"</font><font color="#000000">;<br /> </font><font color="#008000">// Set data source<br /> </font><font color="#000000"> </font><font color="#008080">Try</font><font color="#000000"><br /> excel := </font><font color="#008080">New</font><font color="#000000"> DtExcelProviderEx.Create();<br /> </font><font color="#008000">// Set parameters of the file from which data will be imported<br /> </font><font color="#000000"> excel.File := </font><font color="#800000">"D:\Indicator_Data.xlsx"</font><font color="#000000">;<br /> excel.Sheet := </font><font color="#800000">"Sheet1"</font><font color="#000000">;<br /> excel.Format := </font><font color="#800000">"XLSX"</font><font color="#000000">;<br /> Excel.HasHeader := </font><font color="#008080">False</font><font color="#000000">;<br /> </font><font color="#008000">// Set location of data areas in source file<br /> </font><font color="#000000"> Unpivot := </font><font color="#008080">New</font><font color="#000000"> DtUnpivotProvider.Create();<br /> Unpivot.Provider := Excel;<br /> Unpivot.LeftEnd := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataWidth := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataTop := </font><font color="#008000">3</font><font color="#000000">;<br /> Unpivot.DataBottom := </font><font color="#008000">5</font><font color="#000000">;<br /> Unpivot.HeadBottom := </font><font color="#008000">2</font><font color="#000000">;<br /> Unpivot.DataRight := </font><font color="#008000">8</font><font color="#000000">;<br /> Unpivot.HeadColumn := </font><font color="#008000">1</font><font color="#000000">;<br /> Unpivot.LeftBegin := </font><font color="#008000">1</font><font color="#000000">;<br /> Unpivot.HeadTop := </font><font color="#008000">2</font><font color="#000000">;<br /> </font><font color="#008000">// Load data<br /> </font><font color="#000000"> Unpivot.Open();<br /> count := Unpivot.Fields.Count;<br /> importObject.ProviderParams.Provider := Unpivot </font><font color="#008080">As</font><font color="#000000"> IDatasetDataProvider;<br /> instance := (importObject </font><font color="#008080">As</font><font color="#000000"> IMetabaseObject).Open(</font><font color="#008080">Null</font><font color="#000000">) </font><font color="#008080">As</font><font color="#000000"> IImportRequestInstance;<br /> Instance.LoadData();<br /> </font><font color="#008000">// Get report about data loading<br /> </font><font color="#000000"> importResult := instance.ImportResult;<br /> Log := importResult.Log;<br /> count := Log.Count;<br /> </font><font color="#008000">// Display report to console window<br /> </font><font color="#000000"> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Number of records = "</font><font color="#000000"> + Count.ToString());<br /> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br /> Entry := Log.Item[i];<br /> LogStr := i.ToString() + </font><font color="#800000">": "</font><font color="#000000"><br /> + (Entry.IsError ? </font><font color="#800000">"Error: "</font><font color="#000000"> :(Entry.IsMessage ? </font><font color="#800000">"Message: "</font><font color="#000000"> : </font><font color="#800000">"Warning: "</font><font color="#000000">))<br /> + Entry.ErrorMessage;<br /> System.Diagnostics.Debug.WriteLine(LogStr);<br /> System.Diagnostics.Debug.Indent();<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Record number = "</font><font color="#000000"> + Entry.RecordNumber.ToString());<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Record value = "</font><font color="#000000"> + Entry.ValueRecordNumber.ToString());<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Field in data source = "</font><font color="#000000"> + Entry.Field);<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Number of record in data source = "</font><font color="#000000"> + Entry.SourceRecord.ToString());<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Field number in data source = "</font><font color="#000000"> + Entry.SourceField.ToString());<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Record number in data consumer = "</font><font color="#000000"> + Entry.DestRecord.ToString());<br /> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Field number in data consumer = "</font><font color="#000000"> + Entry.DestField.ToString());<br /> System.Diagnostics.Debug.Unindent();<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br /> </font><font color="#008080">Except</font><font color="#000000"> </font><font color="#008080">On</font><font color="#000000"> e: Exception </font><font color="#008080">Do</font><font color="#000000"><br /> System.Diagnostics.Debug.WriteLine(e.Message);<br /> </font><font color="#008080">Finally</font><font color="#000000"><br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Try</font><font color="#000000">;<br /> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000">;</font>
See also: