我使用OleDb从Excel文件中获取无效的sheetname。怎么了? [英] I am getting invalid sheetname from Excel file using OleDb. What's wrong?
本文介绍了我使用OleDb从Excel文件中获取无效的sheetname。怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string path = Server.MapPath("~/myfolder/myfile.xlsx");
string connExcel= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\";";
connExcel.Open();
DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
connExcel.Close();
sting query ="Select * From [" + SheetName + "]";
推荐答案
替换:
Replace:
sting query ="Select * From [" + SheetName + "]";
with:
with:
sting query =@"Select * From [" + SheetName + "
;
如需了解更多信息,请参阅:
http://www.connectionstrings.com/excel/ [ ^ ]
从.NET应用程序访问Microsoft Office数据 [ ^ ] - 请注意,某些信息已过时。
For further information, please see:
http://www.connectionstrings.com/excel/[^]
Accessing Microsoft Office Data from .NET Applications[^] - note that some piece of information is obsolete.
感谢所有这方面的支持
请再告诉我一个问题
i我从datatable dt制作了一个excelfile xyz但它已经转换了所有数据类型。
datatable dt => excel文件xyz
i必须创建一个txtbox来读取excelfile xyz查询。
txt.text =Select * from [+ sheetname +
thanks to all for this regard
please tell me one more query
i am making a excelfile xyz from datatable dt but its have converted all datatypes.
datatable dt => excel file xyz
i Have to create a txtbox to read excelfile xyz query.
txt.text = "Select * from["+sheetname+"
这篇关于我使用OleDb从Excel文件中获取无效的sheetname。怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文