C#Winform中读取Excel表格数据并显示到DataGridView控件实例

本文讲解Winform中读取Excel表格数据并显示到DataGridView控件实例

首先创建winform项目,添加控件DataGridView和button

修改CS文件

using System;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Windows.Forms;

namespace DataGridviewDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void ReadExcel(string sExcelFile, DataGridView dg)
        {
            DataTable ExcelTable;
            DataSet ds = new DataSet();
            //Excel的连接
            const string cmdText = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;

猜你喜欢

转载自blog.csdn.net/qq_30725967/article/details/132294407