30 lines
983 B
C#
30 lines
983 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ImportPrevuXLSClientData
|
|
{
|
|
class importXlSData
|
|
{
|
|
public DataTable GetData(string fileName, string sheetName)
|
|
{
|
|
|
|
string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + fileName + "';Extended Properties='Excel 12.0;HDR=Yes';";
|
|
OleDbConnection objConn = new OleDbConnection(conn);
|
|
objConn.Open();
|
|
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + sheetName + "$]", objConn);
|
|
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
|
|
objAdapter.SelectCommand = objCmdSelect;
|
|
DataSet objDataset = new DataSet();
|
|
objAdapter.Fill(objDataset);
|
|
objConn.Close();
|
|
DataTable objTable = objDataset.Tables[0];
|
|
return objTable;
|
|
}
|
|
}
|
|
}
|