We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Import excel into DataGrid?

Thread ID:

Created:

Updated:

Platform:

Replies:

29449 May 25,2005 04:55 PM UTC Jun 13,2005 10:43 PM UTC Windows Forms 4
loading
Tags: XlsIO
Administrator [Syncfusion]
Asked On May 25, 2005 04:55 PM UTC

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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On May 27, 2005 05:23 PM UTC

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

Administrator [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;