![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Импортировать БД из Excel [D7]
DART VAIDER © (2004-07-28 09:55:00)Народ помогите плизз как мне импортировать БД из Excel ???
DSKalugin (2004-07-29 19:58:00) [1]кусок моего рабочего модуля.
Набирает в массив данные, а потом - куда хочешь и что хочешь с ними то и делаешь
implementation
uses StrUtils,windows, Variants, Classes, SysUtils, ShellApi, OleServer,COMObj,OleCtnrs,ActiveX, Dialogs;
type
TICPodtvRec=record
SellCod:String;
cnt:SmallInt;
Price:Double;
end;
var ExtrBuff: array of TICPodtvRec;
const xlLandscape=2;
xlPaperA4=9;
var ExcelApp, Workbook, WorkSheet: OLEVariant;
C1,C2 :Variant;
Procedure InitializeExcel;
begin
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := False;
ExcelApp.Application.EnableEvents := false;
end;
Procedure FinalizeExcel;
begin
WorkSheet:=Unassigned;
WorkBook:=Unassigned;
ExcelApp:=Unassigned;
end;
procedure ExtractFrom_XLS_FILE;
var C, i, Idx_FirstStr, Idx_SellCod, Idx_cnt, Idx_Price: Integer;
FSellCod, FCnt, FPrice, ctrl: AnsiString;
OD:TOpenDialog;
begin
OD:=TOpenDialog.Create(nil);
OD.DefaultExt:='xls';
OD.Filter:='Подтверждение|*.xls';
OD.FilterIndex:=0;
OD.Title:='Подтверждение ';
if not OD.Execute then Abort;
try
InitializeExcel;
ExcelApp.Visible := True;
Workbook:=ExcelApp.WorkBooks.Open(OD.FileName);
WorkSheet := Workbook.Worksheets[1];
SetLength(ExtrBuff,0);
Idx_FirstStr:=5; // начало таблицы № 1й строки данных
Idx_SellCod:=2; // № кол = SellCod
Idx_cnt:=4; // № кол = Cnt
Idx_Price:=6; // № кол = Price
C:=1; i:=1;
ctrl:=WorkSheet.Cells[Idx_FirstStr,Idx_SellCod].Value;
while (ctrl<>'') do begin
FSellCod:=WorkSheet.Cells[Idx_FirstStr,Idx_SellCod].Value; // кол = SellCod
FCnt:=WorkSheet.Cells[Idx_FirstStr,Idx_cnt].Value; // кол = Cnt
FPrice:=WorkSheet.Cells[Idx_FirstStr,Idx_Price].Value; // кол = Price
FPrice:=AnsiReplaceStr(FPrice,',','.');
SetLength(ExtrBuff,i);
ExtrBuff[i-1].SellCod:=FSellCod;
ExtrBuff[i-1].cnt:=StrToInt(FCnt);
ExtrBuff[i-1].Price:=StrToFloat(FPrice);
inc(Idx_FirstStr); inc(i);
ctrl:=WorkSheet.Cells[Idx_FirstStr,Idx_SellCod].Value;
end;
finally
OD.Free;
ExcelApp.Quit;
FinalizeExcel;
end;
end;
Вовчик (2004-07-29 18:36:00) [2]QuickImport от EMS
bushmen (2004-07-28 10:40:00) [3]> Народ помогите плизз как мне импортировать БД из Excel ???
А какая БД ?
Anatoly Podgoretsky (2004-07-28 10:38:00) [4]Reindeer Moss Eater © (28.07.04 09:56) [1]
Это уже экспорт.
Надо просто подключить как базу.
Vlad Oshin (2004-07-28 10:31:00) [5]только с кодировками бывают проблемы, бывает надо с БДЕ повозиться
Reindeer Moss Eater (2004-07-28 09:56:00) [6]сохрани лист как dbase