سؤال

I have been using OleDbConnection to read an Excel files from my C# code.

Everything work great when the file has a top header row and the data following it down.

The following connection string is used:

 var query = "SELECT [Col1],[Col2],[Col3] FROM [Sheet1$]";

Now I need to process an Excel file that has an obligatory content from the first down to the 15th row. The 15th row is a header row and the rest is the data for the rows.

How can I read such a file?

هل كانت مفيدة؟

المحلول

To read from 15th row, modify your query to use table name as FROM [Sheet1$A15:ZZ]-

var query = string.Format("select [Col1],[Col2],[Col3] from [{0}${1}]", "Sheet1","A15:ZZ");

A15 represents header row.

Make sure that you have set "HDR=YES" in your connection string.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top