CreateDtObjectFromFile(FileName: String): IDtObject;
CreateDtObjectFromFile(FileName: String): Prognoz.Platform.Interop.Dt.IDtObject;
FileName. Path and name of the file based on which the data source must be created.
The CreateDtObjectFromFile method creates a source linked to the selected file.
File extension and its contents are analyzed when performing the method. A source of specific type and having certain parameters is created according to the analysis result. In the current version this method enables the user to create a source based on the files of the following type:
XLS. Creates the source described by the IDtExcelProvider interface.
XLSX. Creates the source described by the IDtExcelProviderEx interface.
TXT. Creates the source, described by the IDtTextProvider interface.
CSV. Creates the source, described by the IDtTextProvider interface.
Executing the example requires a file named data.txt in the root directory of the disc C.
Sub UserProc;
Var
Creator: IDtObjectCreator;
Provider: IDtProvider;
Path: String = "C:\data.txt";
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
v: Array;
i: Integer;
Begin
Creator := New DtObjectCreator.Create;
Provider := Creator.CreateDtObjectFromFile(Path) As IDtProvider;
(Provider As IDtTextProvider).HeaderRow := 1;
Provider.FieldsFromFile;
Fields := Provider.Fields;
Debug.WriteLine(Fields);
For Each Field In Fields Do
Debug.Write(Field.Name + " ");
End For;
Debug.WriteLine("");
Debug.WriteLine(Values);
Provider.Open;
While Not Provider.Eof Do
Provider.Fetch(v);
For i := 0 To v.Length - 1 Do
Debug.Write(v[i] + " ");
End For;
Debug.WriteLine("");
End While;
Provider.Close;
End Sub UserProc;
The new source linked to the data.txt file is created when executing the example. Fields names and values received from the file are displayed in the development environment output.
Executing the example requires a file named data.txt in the root directory of the disc C.
Imports Prognoz.Platform.Interop.Dt;
Sub UserProc();
Var
Creator: IDtObjectCreator;
Provider: IDtProvider;
Path: String = "C:\data.txt";
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
v: Array;
i: Integer;
Begin
Creator := New DtObjectCreatorClass();
Provider := Creator.CreateDtObjectFromFile(Path) As IDtProvider;
(Provider As IDtTextProvider).HeaderRow := 1;
Provider.FieldsFromFile();
Fields := Provider.Fields;
System.Diagnostics.Debug.WriteLine(Fields);
For Each Field In Fields Do
System.Diagnostics.Debug.Write(Field.Name + " ");
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine(Values);
Provider.Open();
While Not Provider.Eof Do
Provider.Fetch(Var v);
For i := 0 To v.Length - 1 Do
System.Diagnostics.Debug.Write(v[i] + " ");
End For;
System.Diagnostics.Debug.WriteLine("");
End While;
Provider.Close();
End Sub;
The new source linked to the data.txt file is created when executing the example. Fields names and values received from the file are displayed in the development environment output.
See also: