Template Excel untuk Push ke database
Aplikasi Excel memang powerful untuk mekanisme collecting data, terlebih lagi sangat cocok untuk kondisi masyarakat indonesia. Kebanyakan orang indonesia sudah mengenal apa itu aplikasi excel dan aplikasinya baik di kota besar maupun kota kecil. Bahkan sejak SMA sudah mulai dipelajari sebagai ekstrakurikuler. Dalam mekanisme pengumpulan data yang mengharuskan kita mendistribusikan template form isian ke kota-kota kecil, aplikasi excel ini mungkin jadi alternatif solusi yang paling mudah dan powerful digunakan.
Ada dua cara yang bisa dilakukan untuk membaca data excel melalui aplikasi :
1. Menggunakan Instant API Excel-Application yang disediakan oleh beberapa vendor terutama Microsoft.
2. Menggunakan Driver Ms. Jet untuk Excel file
cara yang nomor dua sangat mudah, namun ada beberapa step yang harus diikuti :
1. Mendefinisikan region yang akan didefinisikan sebagai tabel pada file template excel yang akan dijadikan sebagai form isian yang didistribusikan ke semua operator input.
- Pilihan daerah yang akan dijadikan form isian misalkan A1:C4
|
A |
B |
C |
|
1 |
NIM |
Nama |
|
2 |
13596040 |
Samson betawi |
|
3 |
13596041 |
Jhony Depp |
|
4 |
13596042 |
Buce lee |
- Define sebagai tabel mahasiswa : Menu Insert > Name > define
masukkan mahasiswa pada text box Names In workbook - Lalu simpan file excel tersebut
2. dalam aplikasi kita gunakan OLEDB dengan connection string :
sConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\ExcelData.xls;Extended Properties=Excel 8.0;”
3. Open Connection dan Open Query statement (“select * from mahasiswa”), kemudian hasil query bisa disimpan ke container database yang lain.
dibawah ini contoh source code yang bisa digunakan (diambil dari website microsoft : http://support.microsoft.com/kb/311731 )
——————————————————————————————————————————
‘ Create variables that are used in code sample.
Dim i, j As Integer
‘ Create connection string variable. Modify the “Data Source” parameter as
‘ appropriate for your environment.
Dim sConnectionString As String = “Provider=Microsoft.Jet.OLEDB.4.0;” _
& “Data Source=” & Server.MapPath(“../ExcelData.xls”) _
& “;” & “Extended Properties=Excel 8.0;”
‘ Create the connection object by using the preceding connection string.
Dim objConn As New OleDbConnection(sConnectionString)
‘ Open connection with the database.
objConn.Open()
‘ The code to follow uses a SQL SELECT command to display the data from the worksheet.
‘ Create new OleDbCommand to return data from worksheet.
Dim objCmdSelect As New OleDbCommand(“SELECT * FROM myRange1″, objConn)
‘ Create new OleDbDataAdapter that is used to build a DataSet
‘ based on the preceding SQL SELECT statement.
Dim objAdapter1 As New OleDbDataAdapter()
‘ Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect
‘ Create new DataSet to hold information from the worksheet.
Dim objDataset1 As New DataSet()
‘ Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, “XLData”)
‘ Build a table from the original data.
DataGrid1.DataSource = objDataset1.Tables(0).DefaultView
DataGrid1.DataBind()
‘ Clean up objects.
objConn.Close()
——————————————————————————————————————————
No comments yet.




