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.DataSourceF ile.FullFi lePath, 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.
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.DataSourceF
How do I read in the file starting at a certain row for example Row 5 as an example?
Thanks all.
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.CreateO penXmlRead er(fileStr eam);
excelReader.IsFirstRowAsCo lumnNames = 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.
IExcelDataReader excelReader = ExcelReaderFactory.CreateO
excelReader.IsFirstRowAsCo
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
ASKER
tx
What you can do is read data into a data structure like a datatable or an array and then access whatever row you want