Read Data from Excel using Aspose.Cells

Unknown | 9:47 AM |

 <input id="filePathHidden" runat="server"  type="hidden" />
        <asp:FileUpload ID="FileUpload1" runat="server" />
   
        <asp:Button ID="Button1" runat="server"
            Text="Button" onclick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Aspose.Cells;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath(FileUpload1.FileName);
        Workbook workbook = new Workbook();      
        workbook.Open(FileUpload1.PostedFile.InputStream);
        //Get the first worksheet cells collection
        Cells cells = workbook.Worksheets[0].Cells;

        for (int i = 1; i < cells.MaxDataRow; i++)
        {
            for (int j = 0; j < cells.MaxDataColumn; j++)
            {
                Response.Write(cells[i, j].StringValue);

            }
        }
        System.Data.DataTable dt = new DataTable();
     
        dt = cells.ExportDataTable(1, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1);
        dt.Columns[0].ColumnName = "Question";
        dt.Columns[1].ColumnName = "Choice1";
        dt.Columns[2].ColumnName = "Choice2";
        dt.Columns[3].ColumnName = "Choice3";
        dt.Columns[4].ColumnName = "Choice4";
        dt.Columns[5].ColumnName = "Answer";
        dt.AcceptChanges();
        GridView1.DataSource = dt;
        GridView1.DataBind();
     
    }
}

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....