当前位置:首页 » 编程语言 » sqlexcel
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sqlexcel

发布时间: 2022-02-26 01:41:35

‘壹’ 如果excel中想使用sql语句怎么使用

例如简单的从sheet1表中的数据取到表二:
Sub 简单查询()

Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cn.Open "provider=microsoft.jet.oledb.4.0;Extended Properties='Excel 8.0';data source=" & ThisWorkbook.FullName
Sql = "select * from [sheet1$]"
Sheets(2).[A2].CopyFromRecordset cn.Execute(Sql)
MsgBox "取数据成功"
Sheets("sheet2").Select
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub

‘贰’ EXCEL中能不能直接执行SQL语句

1、需要导入的数据如图。

‘叁’ .sql怎么转成excel

.sql文件转成excel表格的步骤:
1、将sql文件放入数据库执行(这边以mysql数据库为例),SQL命令行操作:
sql>@full_path/test.sql;
例:sql>@D:/test.sql;
不需要commit; 一般都是在test.sql 里面最后加上一个commit;
2、从数据库导出数据至excel表格,SQL命令行操作:
sql>select * into outfile 'd:/test.xls' from 表名;
例:sql>select * into outfile 'd:/test.xls' from test;

‘肆’ 如何使用SQL语句实现对Excel工作表数据的查询

--1.开启远程查询支持
execsp_configure'showadvancedoptions',1
reconfigure
execsp_configure'AdHocDistributedQueries',1
reconfigure

--2.链接ExcelMicrosoftACE12.0OLEDBProvider读Excel数据(注意Excel必须事先关闭)
select*from
openrowset('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;DATABASE=C:/Users/nichk/Desktop/data.xls',Sheet1$);

--3.记得用完选项后,关闭这些选项
execsp_configure'AdHocDistributedQueries',0
reconfigure
execsp_configure'showadvancedoptions',0
reconfigure

--4.查看是不是关闭
execsp_configure

记得电脑必须安装oledb提供程序(可搜索AccessDatabaseEngine.exe在微软官网下载安装),不同的版本访问方式不一样,如下是各版本的访问方式:

-->Jet引擎访问Excel97-2003
select*fromOpenRowSet('Microsoft.Jet.OLEDB.4.0','Excel8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls','select*from[Sheet1$]')
select*fromOpenRowSet('Microsoft.Jet.OLEDB.4.0','Excel8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls',[Sheet1$])
select*fromOpenDataSource('Microsoft.Jet.OLEDB.4.0','Excel8.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls')...[Sheet1$]
select*fromOpenDataSource('Microsoft.Jet.OLEDB.4.0','DataSource=D:/97-2003.xls;ExtendedProperties="Excel8.0;HDR=Yes;IMEX=1"')...[Sheet1$]

-->ACE引擎访问Excel97-2003
select*fromOpenRowSet('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls','select*from[Sheet1$]')
select*fromOpenRowSet('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls',[Sheet1$])
select*fromOpenDataSource('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/97-2003.xls')...[Sheet1$]
select*fromOpenDataSource('Microsoft.ACE.OLEDB.12.0','DataSource=D:/97-2003.xls;ExtendedProperties="Excel12.0;HDR=Yes;IMEX=1"')...[Sheet1$]

-->ACE引擎访问Excel2007
select*fromOpenRowSet('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx','select*from[Sheet1$]')
select*fromOpenRowSet('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx',[Sheet1$])
select*fromOpenDataSource('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx')...[Sheet1$]
select*fromOpenDataSource('Microsoft.ACE.OLEDB.12.0','DataSource=D:/2007.xlsx;ExtendedProperties="Excel12.0;HDR=Yes;IMEX=1"')...[Sheet1$]

‘伍’ 怎么用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(!SQLGetInstalledDrivers(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;

‘陆’ 用SQL语句 操作excel

连接字符串
cn.connectionstring=
provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(EXCEL表名) & ";
Extended properties=EXCEL 8.0
打开字符串
sqlstring="select * from [sheet1$]",cn

你自己整理

‘柒’ excel里可以使用sql语句吗

可以的,EXCEL可以作为数据源(SQL语句FROM后面的表),也可以结果存放到EXCEL里面,不过需要使用微软查询(2016版包含)。

‘捌’ 如何在EXCEL中使用SQL进行数据处理与分析

在EXCEL中使用SQL进行数据处理与分析步骤有:

工具原料:excel2013版本

  1. 打开“excel”,在“数据”选项卡中,找到“自其他来源”;




    ‘玖’ sql和excel怎么结合

    将Excel中的数据导入的Access中执行查询操作

    ‘拾’ SQL能用哪些EXCEL公式

    不是的,只是有类似的函数。