Subject Re: {Disarmed} [firebird-support] How to import xls or csv into firebird database table?
Author Hans
This worked for me

unit ExcelUtils;

interface

uses
Windows,
SysUtils,
ComObj,
{$IFDEF VER150}Variants, {$ENDIF}
MyMessages,
Dialogs,
Form_Utils;
var
ExcelApp: OleVariant;

function ExcelOpen(ExcelFile: TFileName): Boolean;
function ExcelClose: Boolean;
function ExcelSaveAsText(TextFile: TFileName): Boolean;
function ExcelNoOfRows: Integer;
function ExcelGoToRowCol(r, c: integer): Boolean;
function ExcelRowColValue(r, c: integer): string;

implementation

function ExcelOpen(ExcelFile: TFileName): Boolean;
begin

try
ExcelApp := GetActiveOleObject('Excel.Application');
except
try
// If no instance of Excel is running, try to Create a new Excel
Object
ExcelApp := CreateOleObject('Excel.Application');
except
MyMessageDlg('Cannot start Excel' + #13 + 'Excel not installed?',
MtError, [mbCancel]);
Result := False;

Exit;
end;
end;

try
ExcelApp.Workbooks.Open(ExcelFile);
ExcelApp.DisplayAlerts := False;
except
Result := False;

ExcelApp.Quit;
ExcelApp := Unassigned;
Exit;
end;

Result := True;
end;

function ExcelClose: Boolean;
begin
Result := True;

begin
try
except
ExcelApp.Workbooks.Close;

ExcelApp.Quit;
ExcelApp := Unassigned;

Result := True;
end;
end;
end;

function ExcelSaveAsText(TextFile: TFileName): Boolean;
const
xlText = -4158;

var
vTemp1, vTemp2, vTemp3: OLEVariant;

begin

try
DeleteFile(TextFile);

vTemp1 := TextFile;
vTemp2 := xlText;
vTemp3 := False;

ExcelApp.ActiveWorkbook.SaveAs(vTemp1, vTemp2, vTemp3);

Result := True;

finally
ExcelApp.Workbooks.Close;

end;
end;

function ExcelNoOfRows: Integer;
const
xlUp = 3;
AColumn = 1;

begin
Result := ExcelApp.Range[Char(96 + AColumn) +
IntToStr(65536)].end[xlUp].Rows.Row;

end;

function ExcelGoToRowCol(r, c: integer): Boolean;
begin
ExcelApp.goto('R' + IntToStr(r) + 'C' + IntToStr(c));

Result := True;
end;

function ExcelRowColValue(r, c: integer): string;
begin
ExcelGoToRowCol(r,c);

Result := ExcelApp.ActiveCell;
end;
end.




----- Original Message -----
From: "SoftTech" <miket@...>
To: <firebird-support@yahoogroups.com>
Sent: Thursday, March 10, 2011 1:13 PM
Subject: Re: {Disarmed} [firebird-support] How to import xls or csv into
firebird database table?


> Greetings Banaru,
>
> I use SMImport to do just that
>
> http://www.scalabium.com/
>
> Mike
>
>
> ----- Original Message -----
> From: Banaru
> To: firebird-support@yahoogroups.com
> Sent: Thursday, March 10, 2011 1:46 PM
> Subject: {Disarmed} [firebird-support] How to import xls or csv into
> firebird database table?
>
>
>
> Hi!
> I have an application (written in delphi using IBDataset)that use
> firebird database. I need to populate some tables with data from other
> clients. This format is xls or i can transform to csv , then to import in
> firebird. I do not want another tools, but dooing that from my
> application.
> How can i do this: importing data from xls or csv in firebird?
> Thanks in advance.
>
>
>
>
> --
> MailScanner Virus/Spam/Malware: PASS (GZ)
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>