DBD::Excel â A class for DBI drivers that act on Excel File.
This is still alpha version.
| Use Case | Command | Description |
|---|---|---|
| Connect to an Excel file | DBI->connect("DBI:Excel:file=test.xls") | đ Open a connection to an Excel workbook |
| Create a table (worksheet) | $hDb->prepare("CREATE TABLE ...")->execute() | đ Create a new worksheet with columns |
| List all worksheets | $hDb->func('list_tables') | đ Return sheet names in the workbook |
| Insert data into a worksheet | $hDb->prepare("INSERT INTO ...")->execute() | đĨ Add rows to a worksheet |
| Select data from a worksheet | $hDb->prepare("SELECT ...")->execute() | đ Retrieve rows from a worksheet |
| Set custom formatter for parsing | connect(..., {xl_fmt => $formatter}) | đ¨ Use a custom formatter class |
| Search Excel files in a directory | $hDr->data_sources({xl_dir => '/path'}) | đ Get list of .xls files in a directory |
use DBI;
$hDb = DBI->connect("DBI:Excel:file=test.xls")
or die "Cannot connect: " . $DBI::errstr;
$hSt = $hDb->prepare("CREATE TABLE a (id INTEGER, name CHAR(10))")
or die "Cannot prepare: " . $hDb->errstr();
$hSt->execute() or die "Cannot execute: " . $hSt->errstr();
$hSt->finish();
$hDb->disconnect();
This is still alpha version.
The DBD::Excel module is a DBI driver. The module is based on these modules:
This module assumes TABLE = Worksheet. The contents of first row of each worksheet as column name.
Adding that, this module accepts temporary table definition at "connect" method with xl_vtbl.
ex. my $hDb = DBI->connect( "DBI:Excel:file=dbdtest.xls", undef, undef,
{xl_vtbl => {TESTV => { sheetName => 'TEST_V', ttlRow => 5,
startCol => 1, colCnt => 4, datRow => 6, datLmt => 4 } } } );
For more information please refer sample/tex.pl included in this distribution.
The following attributes are handled by DBI itself and not by DBD::Excel, thus they all work like expected:
ActiveActiveKidsCachedKidsCompatMode (Not used)InactiveDestroyKidsPrintErrorRaiseErrorWarn (Not used)The following DBI attributes are handled by DBD::Excel:
AutoCommit â Always onChopBlanks â WorksNUM_OF_FIELDS â Valid after $hSt->executeNUM_OF_PARAMS â Valid after $hSt->prepareNAME â Valid after $hSt->execute; undef for Non-Select statements.NULLABLE â Not really working, always returns an array ref of one's. Valid after $hSt->execute; undef for Non-Select statements.These attributes and methods are not supported:
bind_param_inoutCursorNameLongReadLenLongTruncOkAdditional to the DBI attributes, you can use the following dbh attribute:
xl_fmt â This attribute is used for setting the formatter class for parsing.xl_dir â This attribute is used only with data_sources on setting the directory where Excel files ('*.xls') are searched. It defaults to the current directory (".").xl_vtbl â Assumes specified area as a table. See sample/tex.pl.xl_skiphidden â Skip hidden rows (=row height is 0) and hidden columns (=column width is 0). See sample/thidden.pl.xl_ignorecase â Set casesensitive or not about table name and columns. Default is sensitive (maybe as SQL::Statement). See sample/thidden.pl.data_sources â The data_sources method returns a list of '*.xls' files of the current directory in the form DBI:Excel:xl_dir=$dirname.my($hDr) = DBI->install_driver("Excel");
my(@list) = $hDr->data_sources(
{ xl_dir => '/usr/local/xl_data' } );
list_tables â This method returns a list of sheet names contained in the $hDb->{file}. Example:
my $hDb = DBI->connect("DBI:Excel:file=test.xls");
my @list = $hDb->func('list_tables');
Kawai Takanori (Hippo2000) kwitknr AT cpan.org
Homepage:
http://member.nifty.ne.jp/hippo2000/ (Japanese)
http://member.nifty.ne.jp/hippo2000/index_e.htm (English)
Wiki:
http://www.hippo2000.net/cgi-bin/KbWiki/KbWiki.pl (Japanese)
http://www.hippo2000.net/cgi-bin/KbWikiE/KbWiki.pl (English)
DBI, Spreadsheet::WriteExcel, Spreadsheet::ParseExcel, SQL::Statement
Copyright (c) 2001 KAWAI,Takanori All rights reserved.
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-15 06:46 @216.73.217.167
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)