Advertisement
Guest User

Xls_To_MysQl

a guest
Jan 30th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. function Xls_To_MysQl(AXLSFile: string): Boolean;
  2. const
  3. xlCellTypeLastCell = $0000000B;
  4. var
  5. XLApp, Sheet: OLEVariant;
  6. RangeMatrix: Variant;
  7. x, y, k, r: Integer;
  8. Xtanggal,Xid_anggota,Xnama_anggota,Xnik,Xbagian,Xangsuran,Xlokasi :string;
  9. begin
  10. Result := False;
  11. // Create Excel-OLE Object
  12. XLApp := CreateOleObject('Excel.Application');
  13. try
  14. // Hide Excel
  15. XLApp.Visible := False;
  16.  
  17. // Open the Workbook
  18. XLApp.Workbooks.Open(AXLSFile);
  19. Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
  20.  
  21. // In order to know the dimension of the WorkSheet, i.e the number of rows
  22. // and the number of columns, we activate the last non-empty cell of it
  23.  
  24. Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
  25. // Get the value of the last row
  26. x := XLApp.ActiveCell.Row;
  27. // Get the value of the last column
  28. y := XLApp.ActiveCell.Column;
  29. RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
  30.  
  31. // Define the loop for filling in the DBgrid
  32. k := 1;
  33. repeat
  34. for r := 1 to 5 do
  35. begin
  36.  
  37. Xid_anggota := RangeMatrix[K, 1];
  38. Xnama_anggota := RangeMatrix[K, 2];
  39. Xnik := RangeMatrix[K, 3];
  40. Xbagian := RangeMatrix[K, 4];
  41. Xangsuran := RangeMatrix[K, 5];
  42.  
  43. end;
  44.  
  45.  
  46. //input di temporary
  47. with FrmTagihanHutang.ZQuery1 do
  48. begin
  49. Close ;
  50. sql.Clear ;
  51. SQL.Text:='insert into tb_det_pinjaman_pt_tmp(id_anggota,nama_anggota,nik,bagian,angsuran) VALUES ('+
  52. '"'+ Xid_anggota + '","'+ Xnama_anggota + '","'+ Xnik +'","'+ Xbagian +'","'+ Xangsuran +'")';
  53.  
  54. ExecSQL;
  55. end;
  56. Inc(k, 1);
  57. until k > x;
  58. RangeMatrix := Unassigned;
  59.  
  60. finally
  61. // Quit Excel
  62. if not VarIsEmpty(XLApp) then
  63. begin
  64. // XLApp.DisplayAlerts := False;
  65. XLApp.Quit;
  66. XLAPP := Unassigned;
  67. Sheet := Unassigned;
  68. Result := True;
  69. end;
  70. end;
  71. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement