Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Xls_To_MysQl(AXLSFile: string): Boolean;
- const
- xlCellTypeLastCell = $0000000B;
- var
- XLApp, Sheet: OLEVariant;
- RangeMatrix: Variant;
- x, y, k, r: Integer;
- Xtanggal,Xid_anggota,Xnama_anggota,Xnik,Xbagian,Xangsuran,Xlokasi :string;
- begin
- Result := False;
- // Create Excel-OLE Object
- XLApp := CreateOleObject('Excel.Application');
- try
- // Hide Excel
- XLApp.Visible := False;
- // Open the Workbook
- XLApp.Workbooks.Open(AXLSFile);
- Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
- // In order to know the dimension of the WorkSheet, i.e the number of rows
- // and the number of columns, we activate the last non-empty cell of it
- Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
- // Get the value of the last row
- x := XLApp.ActiveCell.Row;
- // Get the value of the last column
- y := XLApp.ActiveCell.Column;
- RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
- // Define the loop for filling in the DBgrid
- k := 1;
- repeat
- for r := 1 to 5 do
- begin
- Xid_anggota := RangeMatrix[K, 1];
- Xnama_anggota := RangeMatrix[K, 2];
- Xnik := RangeMatrix[K, 3];
- Xbagian := RangeMatrix[K, 4];
- Xangsuran := RangeMatrix[K, 5];
- end;
- //input di temporary
- with FrmTagihanHutang.ZQuery1 do
- begin
- Close ;
- sql.Clear ;
- SQL.Text:='insert into tb_det_pinjaman_pt_tmp(id_anggota,nama_anggota,nik,bagian,angsuran) VALUES ('+
- '"'+ Xid_anggota + '","'+ Xnama_anggota + '","'+ Xnik +'","'+ Xbagian +'","'+ Xangsuran +'")';
- ExecSQL;
- end;
- Inc(k, 1);
- until k > x;
- RangeMatrix := Unassigned;
- finally
- // Quit Excel
- if not VarIsEmpty(XLApp) then
- begin
- // XLApp.DisplayAlerts := False;
- XLApp.Quit;
- XLAPP := Unassigned;
- Sheet := Unassigned;
- Result := True;
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement