how to count row columns in excel

Jun 17, 2013 at 6:24 PM
i'm in progress to create an application in c# .
but i got a problem. i want to count how much column and row in excel file but i can't do this.
for example : i browse a file .xlsx. after this, i click OK and program can show number of columns and rows in this .xlsx.
anybody can help me?
thank you
Jun 17, 2013 at 8:37 PM
static void Main(string[] args)
{
  string _PathFilename = @"C:\Temp\tri_201918.xlsx";
  using (FileStream streamIn = File.Open(_PathFilename, FileMode.Open, FileAccess.Read))
  using (IExcelDataReader execlReader = (Path.GetExtension(_PathFilename) == ".xlsx" ? ExcelReaderFactory.CreateOpenXmlReader(streamIn):               ExcelReaderFactory.CreateBinaryReader(streamIn)))
  {
    DataSet ds = new DataSet();
    ds = execlReader.AsDataSet();

    int r = ds.Tables[0].Rows.Count;
    int c = ds.Tables[0].Columns.Count;
At this point, r has the number of rows and c has the number of columns in sheet 0.
Jun 24, 2013 at 5:38 PM
thanks for spend your time to reply my problem.
it helps so much thanks :)