File: String;
File: string;
The File property determines the entire name of the data source file.
The name of the sheet, on which data is located is determined by the IDtExcelProviderEx.Sheet property.
Executing the example requires the C:\Data.xlsx file. Add a link to the Dt system assembly.
Fragment of the C:\Data.xlsx file for which the example is written
Sub UserProc;
Var
ExcelProviderEx: IDtExcelProviderEx;
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
namField, Val: String;
v: Array;
i: Integer;
s: double;
rez: boolean;
Begin
ExcelProviderEx := New DtExcelProviderEx.Create;
ExcelProviderEx.File := "C:\Data.xlsx";
ExcelProviderEx.Sheet := "Sheet1";
ExcelProviderEx.HasHeader := True;
ExcelProviderEx.HeaderRow := 0;
ExcelProviderEx.AutoFillFieldsMode := DtAutoFillFieldsMode.DataRow;
ExcelProviderEx.TypeGuessRows := 5;
ExcelProviderEx.Format := "XLSX";
ExcelProviderEx.DataRow := 1;
ExcelProviderEx.Open;
Fields := ExcelProviderEx.Fields;
Debug.WriteLine("Fileds number: " + Fields.Count.ToString);
namField := "Fields names: ";
// Form a row with fields name
For Each Field In Fields Do
namField := namField + Field.Name + "; "
End For;
Debug.WriteLine(namField);
Debug.WriteLine("Data:");
While Not ExcelProviderEx.Eof Do
Val := "";
ExcelProviderEx.Fetch(v);
// Form row with data
For i := 0 To v.Length - 1 Do
rez := CultureInfo.Current.TryParseDouble(v[i], s);
If Not rez Then
val := val + v[i] + "; ";
Else
val := val + s.ToString + "; ";
End If;
End For;
Debug.WriteLine(val);
End While;
ExcelProviderEx.Close;
End Sub UserProc;
After executing the example in the console window data, read from file C:\Data.xlsx, is displayed.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.ForeSystem;
Public Sub UserProc();
Var
ExcelProviderEx: IDtExcelProviderEx;
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
namField, Val: String;
v: Array;
i: Integer;
s: double;
rez: boolean;
ci: CultureInfoClassClass;
Begin
ExcelProviderEx := New DtExcelProviderEx.Create();
ExcelProviderEx.File := "C:\Data.xlsx";
ExcelProviderEx.Sheet := "Sheet1";
ExcelProviderEx.HasHeader := True;
ExcelProviderEx.HeaderRow := 0;
ExcelProviderEx.AutoFillFieldsMode := DtAutoFillFieldsMode.affmDataRow;
ExcelProviderEx.TypeGuessRows := 5;
ExcelProviderEx.Format := "XLSX";
ExcelProviderEx.DataRow := 1;
ExcelProviderEx.Open();
Fields := ExcelProviderEx.Fields;
System.Diagnostics.Debug.WriteLine("Fields number: " + Fields.Count.ToString());
namField := "Fields names: ";
// Form row with fields names
For Each Field In Fields Do
namField := namField + Field.Name + "; "
End For;
System.Diagnostics.Debug.WriteLine(namField);
System.Diagnostics.Debug.WriteLine("Data:");
ci := New CultureInfoClassClass.Create();
While Not ExcelProviderEx.Eof Do
Val := "";
ExcelProviderEx.Fetch(Var v);
// Form row with data
For i := 0 To v.Length - 1 Do
rez := ci.Current.TryParseDouble(v[i].ToString(), Var s);
If Not rez Then
val := val + v[i] + "; ";
Else
val := val + s.ToString() + "; ";
End If;
End For;
System.Diagnostics.Debug.WriteLine(val);
End While;
ExcelProviderEx.Close();
End Sub;
See also: