//pass file stream and get excel data
//referance link:-http://exceldatareader.codeplex.com/
static void GetAllExcelValues(Stream sourceFileStream)
{
//FileStream sourceFileStream = File.Open(filePath, FileMode.Open, FileAccess.Read);
//1.
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(sourceFileStream);
//...
//2.
//IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(sourceFileStream);
//...
////3. DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader.AsDataSet();
//...
//4. DataSet - Create column names from first row
//excelReader.IsFirstRowAsColumnNames = true;
//DataSet result = excelReader.AsDataSet();
var tableCount = 0;
while (tableCount <>
{
var Sheets = result.Tables[tableCount];
int rowCount = 1;
foreach (DataRow Eachrows in Sheets.Rows)
{
foreach (var CellValue in Eachrows.ItemArray)
{
string CharCount = string.Empty;
var data = CellValue != null ? CellValue : string.Empty;
}
rowCount++;
}
tableCount++;
}
excelReader.Close();
}
No comments:
Post a Comment