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;
using System.Data.OleDb; //命名空间
namespace 读取Excel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//根据excle的路径把第一个sheel中的内容放入datatable
public static DataTable ReadExcelToTable(string folder_path)//excel存放的路径
{
try
{
//连接字符串
string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + @"D:\123.xlsx" + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"; // Office 07及以上版本 不能出现多余的空格 而且分号注意
//string connstring = Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"; //Office 07以下版本
using (OleDbConnection conn = new OleDbConnection(connstring))
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载