C# 在没有安装offcie的机器上,程序导入Excel会报错这个问题如何解决;说这个方法报错:
//得到Excel表名
public static DataTable GetName(string path)
{
string strPath = path;
if (!strPath.EndsWith(".xls"))
{
return null;
}
OleDbConnection ExcelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + strPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'");
OleDbCommand ExcelCommand = new OleDbCommand();
ExcelCommand.Connection = ExcelConnection;
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand); ExcelConnection.Open();
DataTable ExcelSheets = ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); ExcelConnection.Close();
return ExcelSheets;
}
//得到Excel表名
public static DataTable GetName(string path)
{
string strPath = path;
if (!strPath.EndsWith(".xls"))
{
return null;
}
OleDbConnection ExcelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + strPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'");
OleDbCommand ExcelCommand = new OleDbCommand();
ExcelCommand.Connection = ExcelConnection;
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand); ExcelConnection.Open();
DataTable ExcelSheets = ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); ExcelConnection.Close();
return ExcelSheets;
}
http://www.spreadsheetgear.com/不需要安裝officemy blog
http://ufo-crackerx.blog.163.com/
SELECT *
INTO Sheet1 IN 'E:\Book1.xls' 'EXCEL 8.0;'
FROM Table
问题就是出在了:浏览excel文件,是调用上次的方法获取工作的列表。
这种方式也试了,不过还是没有excel服务。