1.要点

string str = "test2.cs";
            Workbook wb = new Workbook();
            wb.LoadFromFile(str);
            DataTable table = wb.Worksheets[0].ExportDataTable();

            dataGridView1.DataSource = table;

2.代码

using Spire.Xls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Excel生产table试验
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            initData();
        }
        private void initData()
        {
            string str = "test2.cs";
            Workbook wb = new Workbook();
            wb.LoadFromFile(str);
            DataTable table = wb.Worksheets[0].ExportDataTable();

            dataGridView1.DataSource = table;
        }
    }
}

3.运行效果

c# 使用 Free Spire.XLS 生成DataTable-LMLPHP

 

04-15 13:27