2017-11-11 3 views
-2

Visual Basic .net 2017にインポートする必要があるOpenOfficeスプレッドシートに、クライアント名、プロジェクト名、従業員名、時間別レートのリストがあります。私はコンボボックスにこれを行うことができますので、ユーザーはドロップダウンリストから名前を選択することができます好ましいです。 SQLサーバーを設定しなければ、これは不可能なようです。誰も私がこれをやっていく方法を知っていますか?Visual Basic .netコンボボックスにスプレッドシート(​​OpenOffice)をインポート

私はこれを試してみたが、それはそれは私がこれはあなたが始めるだろう、YouTubeの動画

Private Sub btnGetSpread_Click(sender As Object, e As EventArgs) Handles btnGetSpread.Click 
    Try 

     Dim MyConnection As System.Data.OleDb.OleDbConnection 
     Dim dataSet As System.Data.DataSet 
     Dim MyCommand As System.Data.OleDb.OleDbDataAdapter 
     Dim path As String = "P:\Coding\Visual Studio\Visual Basic\TestProject\TestProject\bin\Files\Company_Sheet.ods" 

     MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source =" + "P:\Coding\Visual Studio\Visual Basic\TestProject\TestProject\bin\Files\Company_Sheet.ods" + ";Extended Properties=Excel 12.0;") 
     MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) 

     dataSet = New System.Data.DataSet 
     MyCommand.Fill(dataSet) 
     dgvSpread.DataSource = dataSet.Tables(0) 

     MyConnection.Close() 

    Catch ex As Exception 

     MsgBox(ex.Message.ToString) 

    End Try 

End Sub 
+1

あなたは何を試しましたか? – Ibo

+1

投稿する前に[質問]と[ツアー]を読んでください。また、これらのタグのいくつかは相互に排他的です。タグにはガイダンステキストが含まれます。 – Plutonix

+0

これは 'excel'と' vba'にどのように関連していますか? – jsotola

答えて

0

からこのコードを持ってMicrosoft.Ace.OLEDB.12.0 に接続できないことを言います。 ExcelのスプレッドシートからOracleデータベースにデータをインポートする必要がある場合がありますが、このコードは古くても動作します(VS 2013)。あなたの状況に合わせて変更してください。

Dim sourceFile As String = "C:\Users\appdata\Documents\SomeData.xls" 
    Dim srcConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sourceFile & ";Extended Properties=""Excel 8.0;HDR=YES;""" 
    Dim srcConn As OleDbConnection = New OleDbConnection(srcConnString) 
    srcConn.Open() 
    ' in the select statement, the fields are the column names in the spreadsheet and are expected to be in row 1 and are case sensitive 
    ' the from clause in the query is the tab of the spreadsheet where the data is 
    Dim cmdExcel As OleDbCommand = New OleDbCommand("Select NAME,ADDRESS,CITY,STATE,ZIP From [DATA$] Where some where clause", srcConn) 
    Dim drExcel As OleDbDataReader = cmdExcel.ExecuteReader() 
    ' Now loop through the rows in the spreadsheet 
    While drExcel.Read() 
     'Do stuff ... 
    End While 
関連する問題