# perldoc > DBD::Excel

---
type: CommandReference
command: DBD::Excel
mode: perldoc
section: ''
source: perldoc
---

## Quick Reference

- `DBI->connect("DBI:Excel:file=test.xls")` — connect to an Excel file
- `$hDb->prepare("CREATE TABLE sheet (id INTEGER, name CHAR(10))")` — create a new worksheet table
- `$hSt->execute()` — execute a prepared statement
- `$hSt->finish()` — finish a statement handle
- `$hDb->disconnect()` — disconnect from the file
- `$hDb->func('list_tables')` — list sheet names in the file
- `$hDr->data_sources({ xl_dir => '/path' })` — list available Excel files as DBI data sources
- `$hDb->{xl_vtbl} = { ... }` — define a temporary table over a specific cell range

## Name

DBD::Excel - A class for DBI drivers that act on Excel File.

## Synopsis

perl
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();
## Options (Attributes)

### Standard DBI attributes handled by DBD::Excel

- `AutoCommit` — always on
- `ChopBlanks` — works
- `NUM_OF_FIELDS` — valid after `$hSt->execute`
- `NUM_OF_PARAMS` — valid after `$hSt->prepare`
- `NAME` — valid after `$hSt->execute`; undef for non-select statements
- `NULLABLE` — always returns an array ref of ones; valid after `$hSt->execute`; undef for non-select statements

### Driver-specific attributes (`$hDb` properties)

- `xl_fmt` — formatter class for parsing (used when reading files)
- `xl_dir` — directory to search for Excel files when using `data_sources`; defaults to `.`
- `xl_vtbl` — assume a specified cell range as a temporary table; see `sample/tex.pl`
- `xl_skiphidden` — skip hidden rows (height 0) and hidden columns (width 0); see `sample/thidden.pl`
- `xl_ignorecase` — set case sensitivity for table names and columns; default is sensitive (as SQL::Statement); see `sample/thidden.pl`

### Unsupported DBI attributes and methods

- `bind_param_inout`
- `CursorName`
- `LongReadLen`
- `LongTruncOk`

## Examples

**Connect to an Excel file and list sheet names:**

perl
my $hDb = DBI->connect("DBI:Excel:file=test.xls");
my @list = $hDb->func('list_tables');
**List available Excel files in a directory:**

perl
my $hDr = DBI->install_driver("Excel");
my @list = $hDr->data_sources({ xl_dir => '/usr/local/xl_data' });
**Define a temporary table over a specific cell range:**

perl
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,
            }
        }
    }
);
## See Also

- [DBI](http://localhost/phpMan.php/perldoc/DBI/markdown)
- [Spreadsheet::WriteExcel](http://localhost/phpMan.php/perldoc/Spreadsheet::WriteExcel/markdown)
- [Spreadsheet::ParseExcel](http://localhost/phpMan.php/perldoc/Spreadsheet::ParseExcel/markdown)
- [SQL::Statement](http://localhost/phpMan.php/perldoc/SQL::Statement/markdown)