I need to transfer data to SQLite as quickly as possible.
I assume two code passes.
First to determine the type of data
The second one for data filling.
The settings are:
xls.VirtualMode: = True;
xls.IgnoreFormulaText: = True;
The code "OnCellRead" is as follows.
procedure TCellReader.OnCellRead(const sender: TObject; const e: TVirtualCellReadEventArgs);
var
iRow, iCol : Integer;
Clr : TUIColor;
s : String;
b : boolean;
dt2 : TDateTime;
d2 : TDate;
t2 : TTime;
realN : Extended;
fmt : TFlxFormat;
begin
if e.Cell.Sheet <> fSheetToRead then
begin
e.NextSheet := ''; //Stop reading all sheets.
exit;
end;
iRow := e.Cell.Row;
iCol := e.Cell.Col;
case e.Cell.Value.ValueType of
TCellValueType.Empty :
s := '';
TCellValueType.Number :
begin
fmt := excelFile.GetFormat( e.Cell.XF );
if TFlxNumberFormat.HasDateOrTime( fmt.Format ) then
dt2 :=e.Cell.Value.ToDateTime( false )
else
if TFlxNumberFormat.HasDate(fmt.Format) then
d2 := TDate( e.Cell.Value.ToDateTime( false ) )
else
if TFlxNumberFormat.HasDate(fmt.Format) then
t2 := TTime( e.Cell.Value.ToDateTime( false ) )
else
realN := e.Cell.Value.ToNumberInvariant;
end;
TCellValueType.DateTime :
dt2 := e.Cell.Value.ToDateTime( false ); // Spravny 'dd/mm/yyyy hh:mm'. Inak sa neda poznat. Je to cislo dt:=e.Cell.Value.ToDateTime( True); // ZLY
TCellValueType.StringValue :
s := e.Cell.Value.ToSimpleString;// .ToString;
TCellValueType.Boolean :
b := e.Cell.Value.AsBoolean;
TCellValueType.Error :
s := TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToSimpleString;
TCellValueType.Formula :
case e.Cell.value.AsFormula.formulaResult.ValueType of
TFormulaValueType.Empty :
s := '';
TFormulaValueType.Number :
begin
fmt := excelFile.GetFormat( e.Cell.XF );
if TFlxNumberFormat.HasDateOrTime( fmt.Format ) then
dt2 := TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToDateTime( false )
else
if TFlxNumberFormat.HasDate(fmt.Format) then
d2 := TDate( TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToDateTime( false ) )
else
if TFlxNumberFormat.HasDate(fmt.Format) then
t2 := TTime( TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToDateTime( false ) )
else
realN := e.Cell.value.AsFormula.FormulaResult.AsNumber;
end;
TFormulaValueType.StringValue :
s := TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToSimpleString;
TFormulaValueType.Boolean :
b := e.Cell.value.AsFormula.FormulaResult.AsBoolean;
TFormulaValueType.Error :
s := TCellValue( e.Cell.value.AsFormula.FormulaResult ).ToSimpleString;
end;
end;
end;
It is not final, but represents the ability to load all types of cells(I hope)
Please confirm that this is the right solution..?
Or something can be improved.?
I believe that this topic will also benefit other users