๐ Excel(3pm) โ User Contributed Perl Documentation โ Excel(3pm)
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") | Establishes a DBI connection to an Excel workbook |
| ๐ฆ Create a table (worksheet) | $hDb->prepare("CREATE TABLE a (id INTEGER, name CHAR(10))") | Creates a new worksheet with specified columns |
| ๐ List all sheets (tables) | $hDb->func('list_tables') | Returns an array of sheet names in the workbook |
| ๐ Get data source list | $hDr->data_sources( { xl_dir => '/path' } ) | Returns list of Excel files in a directory |
| โ๏ธ Use temporary table definition | DBI->connect(..., { xl_vtbl => { ... } }) | Define a custom table area within a worksheet |
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.
Example:
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 to 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:
$hSt->execute$hSt->prepare$hSt->execute; undef for Non-Select statements.$hSt->execute; undef for Non-Select statements.These attributes and methods are not supported:
bind_param_inout, CursorName, LongReadLen, LongTruncOkAdditional 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 case sensitivity 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
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.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-25 00:00 @216.73.216.179
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)