I need to read an .xlsx file without use 3rd-part library.
I do in this way:
private void Upload(string filename)
{
FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);
// Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
//DataSet - The result of each spreadsheet will be created in the result.Tables
excelReader.IsFirstRowAsColumnNames = false;
DataSet result = excelReader.AsDataSet();
//5. Data Reader methods
string value = GetValue(0, 0, excelReader);
//6. Free resources (IExcelDataReader is IDisposable)
excelReader.Close();
}
I don't know how to read in the right cell. The problem isn't the column position (I can use , but the row position.
public string GetValue(int row, int col, IExcelDataReader excelReader)
{
string s;
// ??? how to positionate on the right row?
s = excelReader(column_value);
return s;
}