文件上传excel在IE中有效,但在chrome中不起作用 [英] File upload excel works in IE but not in chrome

查看:235
本文介绍了文件上传excel在IE中有效,但在chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有这些都是我的代码,文件上载在Internet Explorer中有效,但是当我在chrome中运行它时,它说Microsoft Office Access数据库引擎找不到对象"Sheet1 $".确保该对象存在,并且正确拼写了它的名称和路径名.但是它在Internet Explorer中非常有效.

hi all here is my code the file upload works in internet explorer but when I run it in chrome it says The Microsoft Office Access database engine could not find the object ''Sheet1$''. Make sure the object exists and that you spell its name and the path name correctly. But it works perfectly in internet explorer.

UpdateTimer.Enabled = true;
sw.Start();
int secs = sw.Elapsed.Seconds;

String strConnection = "Data Source=DIVAN-DT;Initial Catalog=test;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
//file upload path
string path = fileuploadExcel.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);


//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[cell],[Title] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "Excel_table";
sqlBulk.WriteToServer(dReader);
sw.Stop();
Label1.Visible = true;
Label1.Text = "Upload Completed in " + sw.Elapsed.Seconds.ToString() + "  Second";
excelConnection.Close();

推荐答案

".确保该对象存在,并且正确拼写了它的名称和路径名.但是它在Internet Explorer中非常有效.

''. Make sure the object exists and that you spell its name and the path name correctly. But it works perfectly in internet explorer.

UpdateTimer.Enabled = true;
sw.Start();
int secs = sw.Elapsed.Seconds;

String strConnection = "Data Source=DIVAN-DT;Initial Catalog=test;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
//file upload path
string path = fileuploadExcel.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);


//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[cell],[Title] from [Sheet1


"中的[Name],[cell],[Title],,excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = SqlBulkCopy(strConnection); // 提供目标表名称 sqlBulk.DestinationTableName = " ; sqlBulk.WriteToServer(dReader); sw.Stop(); Label1.Visible = true ; Label1.Text = " + sw.Elapsed.Seconds.ToString()+ " ; excelConnection.Close();
", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); //Give your Destination table name sqlBulk.DestinationTableName = "Excel_table"; sqlBulk.WriteToServer(dReader); sw.Stop(); Label1.Visible = true; Label1.Text = "Upload Completed in " + sw.Elapsed.Seconds.ToString() + " Second"; excelConnection.Close();


这篇关于文件上传excel在IE中有效,但在chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆