|
-
Sep 9th, 2016, 05:20 PM
#1
Thread Starter
Lively Member
Combine Two Excel Lists
I have two Excel files. One is a DataList and the other is a Matrix. I need to code the Datalist according to the Matrix. So, whatever the values are in the matrix it would populate the Datalist according to the mathcing Offercode. For example.
Here are the data list fields: CustID, First, Name, Address, City, State, Zip, Offercode
Here are the matrix fields: Amount, Date, Expiration, Offercode.
I need the final output to look like this.
(DataList)CustID, (DataList)First, (DataList)Name, (DataList)Address, (DataList)City, (DataList)State, (DataList)Zip, (DataList)Offercode, (Matrix)Amount, (Matrix)Date, (Matrix)Expiration.
To further explain my Vb.net form I have two text boxes and buttons that when pressed browse to the excel files. I then have two comboBoxes that are populated by the headers in the Excel sheets. I want to use to link the tables together. So, like ComboBox1.SelectedItem = ComboBox2.SelectedItem. The theory is that I can load any two lists and map them together as long as the two ComboBox items have the same values within them.
Also, the lists column names will vary moving forward so I need it to select all columns no matter what their header names will be
Not sure how to accomplish this, any help would be great, here is my code thus far:
Code:
Dim xlDirectionLeft As Object = Excel.XlDirection.xlToLeft
Dim xlDirectionRight As Object = Excel.XlDirection.xlToRight
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(DataListFile)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim MyConnection2 As System.Data.OleDb.OleDbConnection
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyCommand2 As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + MatrixFile + ";Extended Properties=Excel 12.0;")
MyConnection2 = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DataListFile + ";Extended Properties=Excel 12.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand2 = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection2)
Dim DtSet1 = New System.Data.DataSet
Dim DtSet2 = New System.Data.DataSet
MyConnection.Open()
MyConnection2.Open()
MyCommand.Fill(DtSet1)
MyCommand2.Fill(DtSet2)
xlWorkBook.Save()
xlApp.Workbooks.Close()
xlApp.Quit()
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|