Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Sender.ConnectionString = Builder.ConnectionStringįile1 and File2 Sheet1 before writing data into File2.xlsx If IO.Path.GetExtension(FileName).ToUpper = ".XLSX" Thenīuilder.Provider = ".12.0"īuilder.Add("Extended Properties", "Excel 12.0 IMEX=" & Mode & " HDR=" & Header.ToString & " ")īuilder.Provider = ".4.0"īuilder.Add("Extended Properties", "Excel 8.0 IMEX=" & Mode & " HDR=" & Header.ToString & " ") IO.Path.Combine(Application.StartupPath, "File2.xls"),ĭim dt As DataTable = DataSet1.Tables("Sheet1")ĮxcelAdapterExport.InsertCommand = New OleDbCommand With IO.Path.Combine(Application.StartupPath, "File1.xls"),ĭim cmd As OleDbCommand = New OleDbCommand(ĮxcelAdapterImport.Fill(DataSet1, "Sheet1") Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Private ExcelAdapterExport As OleDbDataAdapter = New OleDbDataAdapter Private ExcelAdapterImport As OleDbDataAdapter = New OleDbDataAdapter
Private DataSet1 As DataSet = New DataSet() Private cn As OleDbConnection = New OleDbConnection Here is one example where File1.xlsx has data in sheet1 with headers and File2.xlsx has the first row with column headers (if there were none then this method is null and void and another solution is needed) Imports If the second file exists but has no data or headers can make a difference.Įach part can make a difference if the solution works or not.Does the second file exist or do you plan on creating it.Do you want to use OleDb, Office automation (early or late binding), OpenXML SDK etc.Is the first row of the sheet contain data or column names.When dealing with Excel there is no one solution that will resolve what you want.