perl用dbi模块连上excel后,怎么从里面取数据???
useDBI;my$DSNExcel="driver=MicrosoftExcelDriver(*.xls);dbq=E:\\zhanglei.xls";my$dbh=D...
use DBI;
my $DSNExcel = "driver=Microsoft Excel Driver (*.xls);dbq=E:\\zhanglei.xls";
my $dbh = DBI->connect("dbi:ODBC:$DSNExcel",'','');
我用这个命令连上excel文件,但现在不知道取数据的命令,求大侠指教??? 展开
my $DSNExcel = "driver=Microsoft Excel Driver (*.xls);dbq=E:\\zhanglei.xls";
my $dbh = DBI->connect("dbi:ODBC:$DSNExcel",'','');
我用这个命令连上excel文件,但现在不知道取数据的命令,求大侠指教??? 展开
2个回答
展开全部
对于excel的读取,建议用Win32::OLE模块,相当强大和简便
代码如下:
#**********************************************************
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use Cwd;
use File::Find;
use File::Copy;
#*********************************************************************
my $curdir=getcwd();
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')|| Win32::OLE->new ('Excel.Application', 'Quit');
# open Excel file
my $book = $Excel->Workbooks->Open("$curdir\\Header.xls");
#choose the sheet number
my $Sheet = $book->Worksheets(1);
my $name = $Sheet->Cells($row,$col)->{Value};
代码如下:
#**********************************************************
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use Cwd;
use File::Find;
use File::Copy;
#*********************************************************************
my $curdir=getcwd();
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')|| Win32::OLE->new ('Excel.Application', 'Quit');
# open Excel file
my $book = $Excel->Workbooks->Open("$curdir\\Header.xls");
#choose the sheet number
my $Sheet = $book->Worksheets(1);
my $name = $Sheet->Cells($row,$col)->{Value};
展开全部
AFT命令
use snsoftn7_ft_c
从EXCEL中读取内容,也可以将读取的内容插入到数据库的表里
select dictid from dictdef
where dictid
not in
(select convert(smallint,dictid) as dictid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="C:\Documents and Settings\lxl\桌面\data\术语字典.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
select statcode from statlatdef
where statcode
not in
(select convert(smallint,statcode) as dictid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="C:\Documents and Settings\lxl\桌面\data\纬度定义.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
select tblid,tblname,tblexpl from tbldef
where tblid
not in
(select convert(bigint,tblid) as tblid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Documents and Settings\lxl\桌面\data\tbldef.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
use snsoftn7_ft_c
从EXCEL中读取内容,也可以将读取的内容插入到数据库的表里
select dictid from dictdef
where dictid
not in
(select convert(smallint,dictid) as dictid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="C:\Documents and Settings\lxl\桌面\data\术语字典.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
select statcode from statlatdef
where statcode
not in
(select convert(smallint,statcode) as dictid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="C:\Documents and Settings\lxl\桌面\data\纬度定义.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
select tblid,tblname,tblexpl from tbldef
where tblid
not in
(select convert(bigint,tblid) as tblid
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Documents and Settings\lxl\桌面\data\tbldef.xls"
;User ID=Admin;Password=;Extended properties=Excel 5.0')...[sheet1$])
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询