<appSettings>
<add key="preExcelConnectingString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key="endExcelConnectingString" value=";Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"" />
</appSettings>
<add key="preExcelConnectingString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key="endExcelConnectingString" value=";Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"" />
</appSettings>
string endExcelConnectingString=System.Configuration.ConfigurationSettings.AppSettings["endExcelConnectingString"];
openFileDialog1.Filter = "EXCEL工作表文件(*.xlt)|" ; if(openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
//excel文件名
ExcelFilename=openFileDialog1.FileName.ToString();
//数据绑定
string ExcelConnectingString=preExcelConnectingString+ExcelFilename+endExcelConnectingString;
System.Data.DataSet excelDS=new DataSet();
System.Data.OleDb.OleDbDataAdapter excelODA;
System.Data.OleDb.OleDbConnection excelConn=new System.Data.OleDb.OleDbConnection(ExcelConnectingString);
try
{
selStr="select * from ["+ExcelTablename+"$]";
excelODA=new System.Data.OleDb.OleDbDataAdapter(selStr, excelConn); excelODA.Fill(excelDS,"excel");
dataGrid1.SetDataBinding(excelDS,"excel");
dataGrid1.CaptionText="Excel工作表数据";
dataGrid1.Expand(-1);
}
catch(System.Exception e)
{
throw(e);
}
finally
{
excelConn.Close();
} }
我在vs.net里面拉服务里面的控件
然后oledbconnection不能添加excel的连接
odbc可以添加,但是连接里面表下面为空
也就没有办法建立适配器
用Ole直接写代码又可以使用excel
我不想每次都写那么多代码阿
如果能够直接拖工具栏上控件应该是最快最方便的阿
怎么解决