Import excel into DataGrid?

Greetings! I am new to Syncfusion. My co-worker moved on and now I am trying to work with what he left. He was already using SyncfusionExcelRW in his web app, and what I need to be able to do is take an excel sheet and put it into a datagrid. I have searched the web and read through the forum, but I could not find the information that I need. If this is possible, any help would be greatly appreciated. :) Thanks! Kris

4 Replies

AD Administrator Syncfusion Team May 25, 2005 09:36 PM UTC

Okay. I''m moving along a little with this... But I''m still not getting anything into my DataTable using ExportDataTable. Could someone please tell me what I''m doing wrong? Dim excelEngine As ExcelEngine = New ExcelEngine Dim application As IApplication = excelEngine.Excel Dim postedFile As HttpPostedFile = uploadedFile.PostedFile Dim filename As String = Path.GetFileName(postedFile.FileName) Dim myWorkBook As IWorkbook = ExcelUtils.Open(filename) Dim sheet As IWorksheet = myWorkBook.Worksheets(0) Dim lastrow As Integer = sheet.UsedRange.End.Column Dim i As Integer Dim dt As DataTable Dim dt2 As DataTable For i = 1 To lastrow - 1 Step i + 1 ''dt = sheet.ExportDataTable(i, 1, lastrow, 1, True) dt2 = sheet.ExportDataTable(sheet.Range(i + 1, 1), False) Next DataGrid1.DataSource = dt2 DataGrid1.DataBind() DataGrid1.Visible = True Thanks in advance


AD Administrator Syncfusion Team May 27, 2005 04:25 PM UTC

Hi Kris, Sorry for the delay in getting back to you. Please try this Dim dt As DataTable = mySheet.ExportDataTable(mySheet.UsedRange, False) Me.DataGrid1.DataSource = dt Here is a winforms sample that demonstrates the usage, the code is the same for webforms application also Sample Please let me know if you have any questions. Thanks, Stephen. > >Okay. I''m moving along a little with this... >But I''m still not getting anything into my DataTable using ExportDataTable. > >Could someone please tell me what I''m doing wrong? > > Dim excelEngine As ExcelEngine = New ExcelEngine > Dim application As IApplication = excelEngine.Excel > > Dim postedFile As HttpPostedFile = uploadedFile.PostedFile > Dim filename As String = Path.GetFileName(postedFile.FileName) > Dim myWorkBook As IWorkbook = ExcelUtils.Open(filename) > > Dim sheet As IWorksheet = myWorkBook.Worksheets(0) > Dim lastrow As Integer = sheet.UsedRange.End.Column > Dim i As Integer > Dim dt As DataTable > Dim dt2 As DataTable > > > For i = 1 To lastrow - 1 Step i + 1 > > ''dt = sheet.ExportDataTable(i, 1, lastrow, 1, True) > dt2 = sheet.ExportDataTable(sheet.Range(i + 1, 1), False) > > Next > > DataGrid1.DataSource = dt2 > DataGrid1.DataBind() > DataGrid1.Visible = True > >Thanks in advance


AD Administrator Syncfusion Team May 27, 2005 05:23 PM UTC

Is it possible to run in a web app rather than a win form? Thanks, Kris


AD Administrator Syncfusion Team June 13, 2005 10:43 PM UTC

Hi Kris, Please find a web forms version of the sample that loads data from excel into the web Data Grid linked to below: ImportExcelDataGrid_1188.zip Note: There is a Template.xls in the bin folder of the web application. The path to this file is hardcoded in code. Please change this to your environment. Thanks, Davis

Loader.
Up arrow icon