实现的效果:
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
namespace 淘宝单据接收器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string filePath;
private string fileName;
private OleDbConnection conn;
private DataTable readDataTable;
private string connString;
private FileType fileType = FileType.noset;
private enum FileType
{
noset,
xls,
xlsx,
csv
}
//选择路径
private void SetFileInfo(string path)
{
filePath = path;
fileName = this.filePath.Remove(0, this.filePath.LastIndexOf("\\") + 1);
string filettType= fileName.Split('.')[1];
switch (filettType)//判断选择的文件是xls还是XLSX,还是CSV
{
case "xls":
//connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; fileType = FileType.xls;
connString = "Provider=Microsoft.Ace.OleDb.12.0;" + "Data Source=" + path + ";" + "Extended Properties=Excel 8.0; ";
break;
case "xlsx":