Only read used range how to do that ?

May 22, 2013 at 3:05 PM
Hi,

I get all the empty lines below my user data, any who know how to do it.
        int count = 0;

        FileStream stream = File.Open(FilePath, FileMode.Open, FileAccess.Read);

        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
        excelReader.IsFirstRowAsColumnNames = true;

        DataSet ds = excelReader.AsDataSet();
        DataTable dt = new DataTable();

        dt = ds.Tables[Sheet];

        foreach (DataRow dr in dt.Rows)
        {
            Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}", count, dr["ServerName"].ToString(), dr["IP Address"].ToString(), dr["DataCenter"].ToString(), dr["Net Zone"].ToString(), dr["Os"].ToString(), dr["Tasks"].ToString(), dr["Software"].ToString(), dr["Other"].ToString(), dr["Responsible OS/system"].ToString(), dr["Contact Applications"].ToString());
            count++;
        }

        excelReader.Close();