IDtUnpivotProvider.Provider

Syntax

Provider: IDtProvider;

Description

The Provider property determines table data provider containing areas.

Comments

The rest of properties of the interface are used to set up parameters of areas containing in data provider.

Example

Executing the example requires that the file system contains the C:\Data.xls file including data split into areas. Data in file is located in the sheet named Sheet 1. The file system must also contain the C:\DataTransform.txt file where data from C:\Data.xls will be exported.

Add a link to the Dt system assembly.

Contents of the Data.xls file

Sub UserProc;
Var
    XlsProvider: IDtExcelProvider;
    UnpivotProvider: IDtUnpivotProvider;
    FixCells: Array Of Integer;
    TextConsumer: IDtTextConsumer;
    ProviderFields, ConsumerFields: IDtFieldDefinitions;
    i, Row, Col: integer;
    Field, NewField: IDtFieldDefinition;
Begin
    // Create an object for data import from Microsoft Excel files
    XlsProvider := New DtExcelProvider.Create;
    // Specify file with data
    XlsProvider.File := "C:\Data.xls";
    // Specify version of Microsoft Excel driver
    XlsProvider.DriverVersion := "Excel 8.0";

    // Set query for data sampling
    XlsProvider.Query := "Select * From [Sheet1$]";
    // Create an object for working with table data source divided into areas
    UnpivotProvider := New DtUnpivotProvider.Create;
    // Set Microsoft Excel file as a table data source
    UnpivotProvider.Provider := XlsProvider;
    // Set parameters of A4 area
    UnpivotProvider.DataBottom := 10;
    UnpivotProvider.DataRight := 9;
    UnpivotProvider.DataTop := 7;
    UnpivotProvider.DataWidth := 3;
    // Set parameters of A2 area
    UnpivotProvider.HeadBottom := 4;
    UnpivotProvider.HeadColumn := 1;
    UnpivotProvider.HeadTop := 1;
    // Set parameters of A3 area
    UnpivotProvider.LeftBegin := 1;
    UnpivotProvider.LeftEnd := 3;

    // Set fixed cells
    FixCells := New Integer[21];
    FixCells[00] := 1;
    FixCells[10] := 1;
    UnpivotProvider.FixedCells := FixCells;
    // Get fields from data source
    UnpivotProvider.FieldsFromFile;
    // Open data source
    UnpivotProvider.Open;
    // Create an object for data export to text file
    TextConsumer := New DtTextConsumer.Create;
    // Specify output file
    TextConsumer.File := "C:\DataTransform.txt";
    // Set export options
    TextConsumer.WriteHeader := True;

    // Set exported fields
    ProviderFields := UnpivotProvider.Fields;
    ConsumerFields := TextConsumer.Fields;
    For i := 0 To ProviderFields.Count - 1 Do
        Field := ProviderFields.Item(i);
        NewField := ConsumerFields.Add;
        NewField.DataType := Field.DataType;
        NewField.Name := Field.Name;
        NewField.Precision := Field.Precision;
        NewField.Size := Field.Size;
    End For;
    // Open and clear export file
    TextConsumer.Open;
    TextConsumer.Clear;
    // Execute export from table data source divided into areas
    TextConsumer.PutProvider(UnpivotProvider);
    // Get correspondence between cell in output file and cell in source file
    UnpivotProvider.ToSource(10, Row, Col);
    Debug.WriteLine("In output file in cell in row with the 1 index and " +
        "column with the 0 index in source file the cell corresponds in row with the "
        + Row.ToString + " index and column with the index " + Col.ToString);

    // Get correspondence between cell in source file and cell in output file
    UnpivotProvider.FromSource(71, Row, Col);
    Debug.WriteLine("In source file in cell in row with the 7 index and " +
        "column with the 1 index in output file the cell corresponds in row with the "
        + Row.ToString + " index and in column with the index " + Col.ToString);
    // Close data source and exported file
    UnpivotProvider.Close;
    TextConsumer.Close;
End Sub UserProc;

After executing the example the data from the C:\Data.xls file will be transformed and exported in the C:\DataTransform.txt file.

See also:

IDtUnpivotProvider