Arsip: Import file excel dengan format date ke access

more 11 years ago
msih_bljaran
Helllppp.........!!!!
Ane lagi buat SI nih, yg didalemnya tuh import file excell (*.xls) ke delphi. Ane pake OleObject. Nah, salah satu datanya ada yg format tanggal (date) yg di excel. Pas waktu import file, ada pesen kayak gini --> "cannot convert date to string". Plsss,,.... Gmn ya..
Btw ane pake database Access.
Klo misal udah pernah dibahas, mohon dirujuk linknya.

more 11 years ago
Wong_Jowo
blog data tanggal yang ada di excel, trus tekan ctrl+1
Set category DATE yang ada di Tab Number. pilih tipe tanggalnya, dan klik OK. Setelah itu, cek data apakah ada tanggal yang tidak sesuai ketentuan tipe DATE yang dipilih. contohnya tanggal 31 Febuari. tentu saja ga ada. ato tanggal 12 bulan 17.
Kalau emang ketentuan yang ada di excel udah bener,, pasti bisa masuk dech

more 11 years ago
elva_ivana
Coba posting skrip yg telah di buat disini, biar bantunya bisa lebih :D afdol :D

more 11 years ago
safari
Menurutku pada dasarnya di Import dan Export dari dan ke bisa dilakukan. Tapi Khusus Type Date memang memelukan perlakuan khusus deh, Silahkan dicoba dan diperhatikan Format tanggal Standart dari masing-masing Database, aku kasih contoh ya.
Kalo di MySQL format input Tanggalnya adalah YYYY-mm-dd.
YYYY => tahun 4 Digit
mm => Bulan 2 Digit.
dd => Tanggal 2 Digit.
Contoh : 2009-12-25
Selama menginput tanggal walau sumbernya berupa string dan di kirim ke MySQL dengan Type Date kita Formatkan seperti itu pasti masuk.
Nah, bagaimana menginput dari data lain?
Caranya:
1. Cek satu persatu yang akan diambil untuk dikirim, Kalo String => lewat, Integer=> Lewat, kalo Tanggal baru gunakan perlakuan khusus.
2. Bila ketemu sumber bertype Date dan akan dikirim ke Field bertype Date, kita lakukan Parsing untuk kita sesuaikan dengan Model input Data Tujuan.
3. Lakukan Query pengiriman sesuai dengan Data Tujuan
Contoh Data Sumber:
Nomor | Nama | Tgl_Lahir
1 | Agus | 23-02-1975
dikirim ke database MySQL Menjadi
insert into data (Nomor, Nama, Tgl_Lahir) VALUES("1","Agus","1975-02-23")
Mudah2an membantu.
more 11 years ago
msih_bljaran
Nah ini source codenya
function import(tab: TADOQuary; SFile: String): Boolean;
function Tf_utama.import(tab: TADOQuery; SFile: String): Boolean;
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
tgl : String;
x, y, r, no, k : Integer;
label 1;
begin
Result := False;
XLApp := CreateOleObject('Excel.Application');
try
XLApp.Visible:=False;
//XLApp.Visible := False;
XLApp.Workbooks.Open(SFile);
Sheet := XLApp.Workbooks[ExtractFileName(SFile)].WorkSheets[1];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
x := XLApp.ActiveCell.Row;
y := XLApp.ActiveCell.Column;
k:=1;
//x := 2; //nomor baris excel
repeat
if tab.IsEmpty then
no:=1
else if not tab.IsEmpty then
begin
tab.Last;
no:=tab.Fields[0].AsInteger;
no:=no+1;
end;
tab.Append;
tab.Fields[0].AsInteger:=no;
tab.Fields[1].AsString:='im'+IntToStr(no);
tab.FieldByName('tanggal').AsString:=XLApp.Cells.Item[k, 1].Value; ----> Nah ini nih yg bikin masalah
tab.FieldByName('NN1').AsString:= XLApp.Cells.Item[k, 2].Value;
tab.FieldByName('no_faktur').AsString:= XLApp.Cells.Item[k, 3].Value;
tab.FieldByName('nama_customer').AsString:= XLApp.Cells.Item[k, 4].Value;
tab.FieldByName('kota').AsString:= XLApp.Cells.Item[k, 5].Value;
tab.FieldByName('bags').AsString:= XLApp.Cells.Item[k, 6].Value;
tab.FieldByName('nama_barang').AsString:= XLApp.Cells.Item[k, 7].Value;
tab.FieldByName('berat').AsString:= XLApp.Cells.Item[k, 8].Value;
tab.FieldByName('jumlah_harga').AsString:= XLApp.Cells.Item[k, 9].Value;
tab.FieldByName('NN3').AsString:= XLApp.Cells.Item[k, 10].Value;
tab.FieldByName('NN4').AsString:= XLApp.Cells.Item[k, 11].Value;
tab.FieldByName('harga_satuan').AsString:= XLApp.Cells.Item[k, 12].Value;
tab.Post;
k:=k+1;
until XLApp.Cells.Item[k, 1].Value='';
ShowMessage('File telah terimport.');
1:
XLApp.Workbooks.Close;
finally
if not VarIsEmpty(XLApp) then
begin
XLApp.Workbooks.Close;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
Result := True;
end;
end;
end;
------------------------------------------
NB : Source yg ane kasih tanda panah tuh udah pernah coba jadi AsDateTime --> tab.FieldByName('tanggal').AsDateTime=XLApp. ......... bla bla
@wongjowo
cara yg itu udah aq coba tapi tetep belum bisa mas.
Aq sangat berharap bantuan rekan2. Trmakasih.....

more 11 years ago
safari
AKu Ubah Menjadi :
function Tf_utama.import(tab: TADOQuery; SFile: String): Boolean; const xlCellTypeLastCell = $0000000B; var XLApp, Sheet: OLEVariant; tgl : String; x, y, r, no, k : Integer; label 1; begin Result := False; XLApp := CreateOleObject('Excel.Application'); try XLApp.Visible:=False; //XLApp.Visible := False; XLApp.Workbooks.Open(SFile); Sheet := XLApp.Workbooks[ExtractFileName(SFile)].WorkSheets[1]; Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; x := XLApp.ActiveCell.Row; y := XLApp.ActiveCell.Column; k:=1; //x := 2; //nomor baris excel repeat if tab.IsEmpty then no:=1 else if not tab.IsEmpty then begin tab.Last; no:=tab.Fields[0].AsInteger; no:=no+1; end; tab.Append; tab.Fields[0].AsInteger:=no; tab.Fields[1].AsString:='im'+IntToStr(no); Tgl:= XLApp.Cells.Item[k, 1].Value; //-- Format Tanggal Excel => 'mm/dd/YYYY //-- Ubah tanggal tg:= copy(Tgl,1,2); bl:= copy(Tgl,3,2); th:= copy(tgl,5,4); tgl:= th+'-'+bl+'-'+tg //-- Akhir Ubah Tanggal => YYYY-mm-dd //Bila Posisi Tanggalnya tidak diketahui, mending di lakukan pengecekan dulu, apakah itu format tanggal atau bukan. Dan Buatkan Fungsi tersendiri untuk mengecek dan mengubahnya. //-- Untuk Format ke databasenya tinggal atur aja dgn melihat format input tanggal pada Databasenya, contoh ini aku gunakan bila kita menggunakan MySQL tab.FieldByName('tanggal').AsString:=tgl; //XLApp.Cells.Item[k, 1].Value; ----> Nah ini nih yg bikin masalah tab.FieldByName('NN1').AsString:= XLApp.Cells.Item[k, 2].Value; tab.FieldByName('no_faktur').AsString:= XLApp.Cells.Item[k, 3].Value; tab.FieldByName('nama_customer').AsString:= XLApp.Cells.Item[k, 4].Value; tab.FieldByName('kota').AsString:= XLApp.Cells.Item[k, 5].Value; tab.FieldByName('bags').AsString:= XLApp.Cells.Item[k, 6].Value; tab.FieldByName('nama_barang').AsString:= XLApp.Cells.Item[k, 7].Value; tab.FieldByName('berat').AsString:= XLApp.Cells.Item[k, 8].Value; tab.FieldByName('jumlah_harga').AsString:= XLApp.Cells.Item[k, 9].Value; tab.FieldByName('NN3').AsString:= XLApp.Cells.Item[k, 10].Value; tab.FieldByName('NN4').AsString:= XLApp.Cells.Item[k, 11].Value; tab.FieldByName('harga_satuan').AsString:= XLApp.Cells.Item[k, 12].Value; tab.Post; k:=k+1; until XLApp.Cells.Item[k, 1].Value=''; ShowMessage('File telah terimport.'); 1: XLApp.Workbooks.Close; finally if not VarIsEmpty(XLApp) then begin XLApp.Workbooks.Close; XLApp.Quit; XLAPP := Unassigned; Sheet := Unassigned; Result := True; end; end; end;Semoga membantu

more 11 years ago
Wong_Jowo
@msih_bljaran: NB : Source yg ane kasih tanda panah tuh udah pernah coba jadi AsDateTime --> tab.FieldByName('tanggal').AsDateTime=XLApp. ......... bla blayang tebel itu menjadi lebih singkat menjadi formatdatetime('yyyy-mm-dd', tab.fieldbyname('tanggal').AsDateTime) := XLapp. ...............bla bla bla
more ...
- Pages:
- 1
reply |
Report Obsolete
Last Articles
- Lazarus Release 2.0.12
- Project Group dalam Lazarus
- FastPlaz Database Explorer
- Release: FastPlaz Super Mom v0.12.22
- PascalClass #3: Web Development with Free Pascal
- Makna Pascal di Pascal Indonesia
- Kulgram : Instalasi Lazarus di Perangkat Berbasis ARM
- PascalClass #1: Analisa Database dan Machine Learning
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
- Mengenal OXYGENE – Pascal For .NET
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 6 months ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 6 months ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 7 months ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 7 months ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 7 months ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 7 months ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 1 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 8 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 8 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 8 years ago
Random Topic
- membuat alat Input/Output via Tcomport
by Ijal_palu in Tip n Trik Pemrograman more 14 years ago - Sinkronisasi 2 client
by madi in Paradox more 13 years ago - Beda BDE dan ADO
by hendrikwjy in MySQL more 15 years ago - menampilkan animasi flash dgn ekstensi.swf
by anthadi in Tip n Trik Pemrograman more 12 years ago - laporan ttg Turbo Delphi
by simba in Hal umum tentang Pascal Indonesia more 14 years ago - dbchart
by santi in Hal umum tentang Pascal Indonesia more 12 years ago - Mohon bantuan teman2
by grounders in Hal umum tentang Pascal Indonesia more 15 years ago - Pencarian dg 2 parameter?
by rose_see in MySQL more 13 years ago - Borland mo misahin divisi IDE.. sapa yg mo beli hayo..?
by deLogic in OOT more 15 years ago - Baca Port serial
by botrew in Network, Files, I/O & System more 14 years ago