Loading Excel sheet into gridview(datagrid) in asp.net2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ammu001
    New Member
    • Oct 2006
    • 3

    Loading Excel sheet into gridview(datagrid) in asp.net2.0

    I got this much information regarding excel file I want to display.
    strFileName contains the entire file path.


    Dim theWorkbook As Excel.Workbook
    theWorkbook = excelobj.Workbo oks.Open(strFil eName, 0, True, 5, "", "", True, Excel.XlPlatfor m.xlWindows, "\t", False, False, 0, True)
    Dim sheets As Excel.Sheets = theWorkbook.Wor ksheets


    I am not able to index them like
    sheets(1) or sheets.item(1).
    Also there is no function like sheets(1).getIt em
    I want to get the name of all spreadsheets in that excel file.
    Later i have to use it in the place of [General Shift$] in

    Dim myCommand As New OleDbDataAdapte r("SELECT * from [General Shift$]", strConn) '[General Shift$]
    Dim myDataSet As New DataSet()
    myCommand.Fill( myDataSet, "ExcelInfo" )
    GridView1.DataS ource = myDataSet.Table s("ExcelInfo"). DefaultView
    GridView1.DataB ind()


    Please help .
  • kphanira
    New Member
    • Oct 2006
    • 2

    #2
    strFileName contains the entire file path.


    Excel.Applicati onClass objExcel = new Excel.Applicati onClass();

    Excel.Workbooks objBooks = (Excel.Workbook s)objExcel.Work books;

    objBooks.Open(s trFileName,
    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,M issing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,M issing.Value, Missing.Value);

    string sheetname= ((Excel.Workshe et)objBooks.get _Item(1).Worksh eets.get_Item(1 )).Name;

    this may help u...
    let me know your comments

    Comment

    • mady1380
      New Member
      • Sep 2006
      • 18

      #3
      hi

      just check this code..u can probably read it from Excel ..


      *************** *************** *************** *************** *********
      Dim MyExcel As Microsoft.Offic e.Interop.Excel .Application
      Dim MyWorkbook As Microsoft.Offic e.Interop.Excel .Workbook
      Dim MySheet As Microsoft.Offic e.Interop.Excel .Worksheet
      Dim MyCell As Microsoft.Offic e.Interop.Excel .Range

      MyExcel = New Microsoft.Offic e.Interop.Excel .Application
      MyExcel.Workboo ks.Open("C:\Ine tpub\wwwroot\Ad dNewPromotion\E xcel1.xls", , False)
      MyWorkbook = MyExcel.Applica tion.ActiveWork book
      MySheet = MyWorkbook.Acti veSheet
      Label1.Text() = MySheet.Cells.I tem(1, 1).value
      *************** *************** *************** *************** *****
      probably u will be able to read the data from Excel with this code..

      Comment

      Working...