Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

C# - Creating FileStream start at certain row?

Hello all,

I am reading in an excel file into a FileStream as I am using an excel reader with that stream.  User will be inputting what row is the header row in a particular file.  Have files that come in where I need to eliminate some garbage header rows from the file.  So right now I have for example:

FileStream fileStream = new FileStream(dto.DataSourceFile.FullFilePath, FileMode.Open, FileAccess.Read);

How do I read in the file starting at a certain row for example Row 5 as an example?

Thanks all.
Avatar of YZlat
YZlat
Flag of United States of America image

you can't do that.

What you can do is read data into a data structure like a datatable or an array and then access whatever row you want
Avatar of sbornstein2
sbornstein2

ASKER

Well essentially I want to use the DataTable.ColumnName as the end result to get the column name.  The excel reader code gets it into a dataset:

 IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileStream);
                excelReader.IsFirstRowAsColumnNames = true;
               
                DataSet ds = excelReader.AsDataSet();
                DataTable dt = ds.Tables[0];

Then I was going to loop through the column count get the columnname.  The IsFirstRow flag sets the dataset column names.  Problem is the 1st row is not my header row in certain scenarios.  I do not want to use Microsoft Interop at all as it sucks.
ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ya I may have to just delete from the datatable at that point.  just need to make sure I dont have too many columns etc. without the header.
Is the problem in the columns or in the rows?
tx