Individual Sheet

Nov 7, 2009 at 3:18 PM

Hi....I have just started testing out this. Looks great. Congratulations.

 

Just one question.....is it possible to specify the particular sheet one wants to read data off? If not, then how does one loop thru th eindividual sheets. How can one get the name of teh individual sheet?

Any help woudl be much appreciated

RB

May 13, 2011 at 2:36 PM

sheets become tables

            if (File.Exists(@"c:\working\test.xls")) {

                FileStream stream = File.Open(@"c:\working\test.xls", FileMode.Open, FileAccess.Read);

                IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                //IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                excelReader.IsFirstRowAsColumnNames = true;
           
                DataSet result = excelReader.AsDataSet();
                textBox1.Text = result.Tables[0].TableName.ToString() + Environment.NewLine;
               
                int row_no = 0;

                while (row_no < result.Tables[0].Rows.Count)
                {
                    for (int i = 0; i < result.Tables[0].Columns.Count; i++)
                    {
                        textBox1.Text = textBox1.Text + result.Tables[0].Rows[row_no][i].ToString() + ",";
                    }
                    row_no++;
                    textBox1.Text = textBox1.Text + Environment.NewLine;
                }

                excelReader.Close();
            }