读取用户上传的EXCEL 数据
private void btnBrown_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "excel file(*.xlsx)|*.xlsx|excel file(*.xls)|*.xls";
if (openFile.ShowDialog() == DialogResult.OK)
{
txtFilename.Text = openFile.FileName.ToString().Trim();
}
}
public DataSet ExceltoDataSet(string FileName, bool ContainName)
{
DataSet ds = new DataSet();
OleDbConnection cn = null;
FileInfo file = new FileInfo(FileName);
string extension = file.Extension;
switch (extension)
{
case ".xls":
cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + "; Jet OLEDB:Engine Type=5;Extended Properties=\"Excel 8.0;\"");
break;
case ".xlsx":
cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + "; Jet OLEDB:Engine Type=5;Extended Properties=\"Excel 12.0;\"");
break;
default:
cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + "; Jet OLEDB:Engine Type=5;Extended Properties=\&#