Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Read xls/xlsx and display on screen

$
0
0
Hey guys....so i'm using 'Excel data reader' to read in an excel file, I then want to display the file on screen.
     protected void Page_Load(object sender, EventArgs e)
    {
        string filePath = @"C:\WORK\BoireannSVN\trunk\VS\CRCConnect\Spreadsheet\Spreadsheet.xlsx";

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

        IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
     
        excelReader.IsFirstRowAsColumnNames = true;
        DataSet result = excelReader.AsDataSet();

        while (excelReader.Read())
        {
            Label x = new Label();
            x.Text = result.Tables[0].Rows[0].ItemArray[0].ToString();
            uploadExcel.Controls.Add(x); 

            excelReader.GetInt32(0);
        }

        excelReader.Close();

    }


I've added in the
    Label x = new Label(); 
    x.Text = result.Tables[0].Rows[0].ItemArray[0].ToString();



Attempting to get the excel sheet to display on screen, although I'm having no luck with this. I think it is something like
    table1.Columns.Add;
    table1.Rows.Add;



but can't seem to get it going, ay help much appreciated.
Thank You

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>