How to merge two Excel workbook into one workbook in C#?

后端 未结 4 1168
渐次进展
渐次进展 2021-01-03 17:04

Let us consider that I have two Excel files (Workbooks) in local. Each Excel workbook is having 3 worksheets.

Lets say WorkBook1 is having Sheet1, Sheet2, Sheet3

4条回答
  •  萌比男神i
    2021-01-03 17:36

     System.Data.Odbc.OdbcDataAdapter Odbcda;
    
    //CSV File
    strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + SourceLocation + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
    
    sqlSelect = "select * from [" + filename + "]";
    
    System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(strConnString.Trim());
    
    conn.Open();
    Odbcda = new System.Data.Odbc.OdbcDataAdapter(sqlSelect, conn);
    Odbcda.Fill(ds, DataTable);
    conn.Close();
    
    • This would read the contents of an excel file into a dataset.
    • Create multiple datasets like this and then do a merge.

    Code taken directly from here.

提交回复
热议问题