Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

excel

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

string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtPath.Text);
string query = String.Format("select * from [{0}$]", "Sheet1");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];    
like image 529
amer Avatar asked Aug 22 '11 16:08

amer


People also ask

How do I select only certain columns in Excel?

Select one or more rows and columns Or click on any cell in the row and then press Shift + Space. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

How do I extract specific columns in Excel spreadsheet?

Press Ctrl-m and choose the Extract Columns from Data Range option. Fill in the dialog box that appears with the Input Range and Output Range as shown in Figure 1 and then click on the OK button.

How do I select columns by columns in Excel?

You can also click anywhere in the table column, and then press CTRL+SPACEBAR, or you can click the first cell in the table column, and then press CTRL+SHIFT+DOWN ARROW. Note: Pressing CTRL+SPACEBAR once selects the table column data; pressing CTRL+SPACEBAR twice selects the entire table column.


1 Answers

What about:

SELECT * FROM [Sheet1$B14:C20]

This should select cells B14 to C20.

like image 108
Kev Avatar answered Oct 19 '22 19:10

Kev