Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to extract the data present in the bill which is in excel
Skipping the header content and add that data in datagridview. How can I do it?
I have created a windows form.
Posted
Updated 24-Mar-13 5:02am
v2
Comments
Maciej Los 24-Mar-13 10:57am    
What have you done till now?
WinForms? WebControls?
Please, be more specific and provide more details.
[no name] 24-Mar-13 11:10am    
"How can I do it?", you write some code that is how you would do it.
Member 9399007 24-Mar-13 11:15am    
I am able to pick the contents from normal excel sheet and put it in datagridview but the problem is of the bill with the bill format containing not only the table needed but also the extra stuff such as header
Maciej Los 24-Mar-13 11:36am    
Share your code.
Improve your question and add more details. Does "extra stuff" is embeded in Excel file?
If you can import the content of MS Excel file, where is a problem?

For reading Excel there are lots of examples from the official microsoft documentation which a google search should provide for you:

http://support.microsoft.com/kb/302084[^]

You could use OLEdb connection also.
 
Share this answer
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Import_Excel_file_into_DataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            DialogResult dlgResult = dlg.ShowDialog();
            if (dlgResult == DialogResult.OK)
            {
                txtPath.Text = dlg.FileName;
            }
        }

        private void btnLoadData_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(txtPath.Text))
            {
                string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtPath.Text);
                string query = String.Format("select * from [{0}$]", "Sheet1");
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(dataSet);
                dataGridView1.DataSource = dataSet.Tables[0];               
            }
            else
            {
                MessageBox.Show("No File is Selected");
            }
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900