How can i select specific columns from excel sheet in c#?

前端 未结 3 1122
深忆病人
深忆病人 2020-12-10 19:43

How can I select specific columns from excel sheet rather than all columns

string connectionString = String.Format(@\"Provider=Microsoft.ACE.OLEDB.12.0;Data         


        
相关标签:
3条回答
  • 2020-12-10 20:22

    What about:

    SELECT * FROM [Sheet1$B14:C20]
    

    This should select cells B14 to C20.

    0 讨论(0)
  • 2020-12-10 20:28

    If you want to select the data before populating here is a good reference on advanced select statements. If you want to manipulate your data post populating your DataSet then here's how:

    DataTable myTable = dataSet.Tables[0];
    
    var myColumn = myTable.Columns["ColumnName"];
    

    or

    var myColumn = myTable.Columns[0];
    

    To access a single field it would look something like this.

    var field = myTable.Rows[0][myColumn];
    
    0 讨论(0)
  • 2020-12-10 20:37

    This will sound trivial but this is what I understand from your question. Instead of SELECT * use SELECT [columnName1],[columnName2] FROM Sheet1.. Here columnName1 and columnName2 should be the headers of columns that you want to get from Excel Sheet.

    0 讨论(0)
提交回复
热议问题