Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2008, 11:07 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lucho1970
Default

Please give me an idea or do all my work for me by going to google and searching for c# import excel datagridview.

Funny... This is similar to what I searched for in Google and I get a bit of a comic relief instead!

Unfortunately, these types of responses also gives you more junk to have to weed through before you get an actual answer to your question.

I agree that you cannot just jump on a forum and ask for the answer... I have answered many questions on many forums in the past and I have yet to ask one myself. Maybe it's time for me to stop answering and just ask people to start doing my work for me... :)
No, not yet!

Good day all!!



 
Old March 5th, 2010, 05:28 AM
Registered User
 
Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

with this Excel C# component you can easily import Excel to DataTable and then bind it to DataGridView.

Here is a code snippet:
Code:
ExcelFile ef =  new ExcelFile();
DataTable dataTable = new DataTable();

// Depending on the format of the input file, you need to change this:
dataTable.Columns.Add("FirstName", typeof(string));
dataTable.Columns.Add("LastName", typeof(string));

// Load Excel file.
ef.LoadXls("FileName.xls");

// Select the first worksheet from the file.
ExcelWorksheet ws = ef.Worksheets[0];

// Extract the data from the worksheet to the DataTable.
// Data is extracted starting at first row and first column for 10 rows or until the first empty row appears.
ws.ExtractToDataTable(dataTable, 10, ExtractDataOptions.StopAtFirstEmptyRow, ws.Rows[0], ws.Columns[0]);

// Bind DataTable to dataGridView
dataGridView.DataSource = dataTable;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Import from Excel sheet to a text file zone Excel VBA 1 July 26th, 2007 10:34 AM
Import & Export Excel File prasanta2expert ASP.NET 1.0 and 1.1 Basics 5 March 5th, 2007 09:28 AM
Excel Vs CSV file - import performance itHighway Classic ASP Databases 0 August 5th, 2006 03:40 PM
Import an excel file into access arjunvs Access VBA 1 September 15th, 2004 07:21 PM
How to import Excel file to vc++ editor lokanadham Beginning VB 6 0 September 15th, 2004 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.