当前位置:首页教育技巧excel技巧excel表格单元

sql怎么搜excel表格

2025-01-09 15:46:21


1.怎么用sql语句读取excel文件啊

//for get driver。

char szBuf[2001]; WORD cbBufMax = 2000; WORD cbBufOut; char *pszBuf = szBuf; CString sDriver;//for read the file。CDatabase database; CString sSql; CString sItem1,sItem2; CString sDsn; CString sFile;//-------------------在这里把sFile赋值为你要读取的xls文件的文件名.///////////////////////////////////////// Get the names of the installed drivers////////////////////////////// if(!(szBuf,cbBufMax,& cbBufOut)) sDriver=""; else { // Search for the driver。

do { if( strstr( pszBuf, "Excel" ) != 0 ) { // Found ! sDriver = CString( pszBuf ); break; } pszBuf = strchr( pszBuf, '\0' ) + 1; } while( pszBuf[1] != '\0' ); }// Retrieve the name of the Excel driver. This is // necessary because Microsoft tends to use language// specific names like "Microsoft Excel Driver (*.xls)" versus// "Microsoft Excel Treiber (*.xls)"// sDriver = GetExcelDriver(); if( sDriver.IsEmpty() ) { AfxMessageBox("No Excel ODBC driver found"); exit(0); } sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { // Open the database using the former created pseudo DSN database.Open(NULL,false,false,sDsn); // Allocate the recordset CRecordset recset( &database ); // Build the SQL string // Remember to name a section of data in the Excel sheet using "Insert->Names" to be // able to work with the data like you would with a table in a "real" database. There // may be more than one table contained in a worksheet.sSql = "SELECT [A],[B]" //把A,B为xls文件里面的列,如果要读取多列的话,用,隔开 "FROM [Sheet1$] " //xls文件里面的第一个表,如果xls文件里的第一个表不是Sheet1这个名字的话,最好改为Sheet1 "ORDER BY [A],[B]"; //从小到大输出,A列为一级,B列为二级 // Execute that query (implicitly by opening the recordset) recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly); // Browse the result while( !recset.IsEOF() )//不断读取A,B列的数据 { //Read the result line recset.GetFieldValue("A",sItem1); //把A列的数据传给sItem1 recset.GetFieldValue("B",sItem2); //把B列的数据传给sItem2 //注意!这里的sItem1,sItem2是不断更新的 // Close the database database.Close(); } CATCH(CDBException, e) { // A database exception occured. Pop out the details。 AfxMessageBox("Database error: "+e->m_strError); } END_CATCH;。

2.sql导入excel数据怎么能找到

方法如下:

1、打开要导入的Excel文件,观察第一列是为字段还是数据。

2、打开SQLServer,在需要导入的数据点击右键 【任务】-【导入数据】

出现导入导出向导。

3、点击下一步 ,进入【选择数据源】页面,注意红框设置。

4、点击下一步 ,进入【选择目标】页面,注意红框设置。

5、点击下一步 ,进入【指定表复制或查询】页面,注意红框设置。

6、点击下一步 ,进入【选择源表和源视图】页面,注意红框设置。

7、下一步,直到完成。出现【执行结果页面】。

8、最后在SqlServer查询表。

附上出处链接:

3.如何在sql中查询excel表格

举例百,度参考专:属

Public Function SQLTest()

Dim strSQL As String

Dim strMyString As String

strMyString = "jason"

strSQL = "SELECT * FROM tblMain " & _

"WHERE [TextField] = strMyString"

Debug.Print strSQL

CurrentDb.OpenRecordset strSQL

End Function

4.如何用SQL语句查询Excel数据

Set conn = CreateObject("adodb.connection")conn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullNameSql = "select * from [sheet1$a:d]"[f4].CopyFromRecordset conn.Execute(Sql)conn.Close: Set conn = Nothing。

5.如何使用SQL语句实现对Excel工作表数据的查询

--1.开启远程查询支持 exec sp_configure 'show advanced options' ,1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure--2.链接Excel Microsoft ACE 12.0 OLE DB Provider 读Excel数据(注意Excel必须事先关闭) select * from openrowset('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;DATABASE=C:/Users/nichk/Desktop/data.xls', Sheet1$);--3.记得用完选项后,关闭这些选项 exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure--4.查看是不是关闭 exec sp_configure记得电脑必须安装oledb提供程序(可搜索AccessDatabaseEngine.exe在微软官网下载安装),不同的版本访问方式不一样,如下是各版本的访问方式:--> Jet 引擎访问 Excel 97-2003 select * from OpenRowSet('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls', 'select * from [Sheet1$]') select * from OpenRowSet('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls', [Sheet1$]) select * from OpenDataSource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls')。

[Sheet1$] select * from OpenDataSource('Microsoft.Jet.OLEDB.4.0', 'Data Source=D:/97-2003.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"')。[Sheet1$] --> ACE 引擎访问 Excel 97-2003 select * from OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls', 'select * from [Sheet1$]') select * from OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls', [Sheet1$]) select * from OpenDataSource('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls')。

[Sheet1$] select * from OpenDataSource('Microsoft.ACE.OLEDB.12.0', 'Data Source=D:/97-2003.xls;Extended Properties="Excel 12.0;HDR=Yes;IMEX=1"')。[Sheet1$] --> ACE 引擎访问 Excel 2007 select * from OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx', 'select * from [Sheet1$]') select * from OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx', [Sheet1$]) select * from OpenDataSource('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx')。

[Sheet1$] select * from OpenDataSource('Microsoft.ACE.OLEDB.12.0', 'Data Source=D:/2007.xlsx;Extended Properties="Excel 12.0;HDR=Yes;IMEX=1"')。[Sheet1$]。

6.如何用sql语句查询exce工作表

如何用sql语句查询exce工作表

在通过ADO对Excel对象进行连接时(此时Excel则认为是一个数据源),需要配置对Excel数据源对应的连接串,这个连接串中包括了Provider信息(其实类似对数据库进行连接操作时,都需要指定连接字符串),以下是一行连接串源代码: strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strExcelFilePath & ";Extended Properties=Excel 12.0" 这里的Provider使用了Microsoft.ACE.OLEDB.12.0,

相关信息


电脑版

【免责声明】本站信息来自网友投稿及网络整理,内容仅供参考,如果有错误请反馈给我们及时更正,对文中内容的真实性和完整性本站不提供任何保证,不承但任何责任。
版权所有:学窍知识网 Copyright © 2011-2025 www.at317.com All Rights Reserved .