DBD::Excel(3pm)

πŸ“¦
version 0.07 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– DBD::Excel πŸ’–

okay bestie, so this is DBD::Excel β€” a class for DBI drivers that act on Excel File ✨ and yes it is still alpha version, she's a work in progress and we love her anyway πŸŽ€

(also this whole page lives in the User Contributed Perl Documentation section, iykyk πŸ’…)


✨ SYNOPSIS ✨

use DBI;
my $dbh = DBI->connect("DBI:Excel:file=test.xls") or die "Cannot connect: " . $DBI::errstr;
my $sth = $dbh->prepare("CREATE TABLE a (id INTEGER, name CHAR(10))") or die "Cannot prepare: " . $dbh->errstr();
$sth->execute() or die "Cannot execute: " . $sth->errstr();
$sth->finish();
$dbh->disconnect();

like look at her go, connecting, preparing, executing, finishing, disconnecting β€” full main character arc fr fr πŸ‘‘


🌸 DESCRIPTION 🌸

okay so first things first: this is still alpha version. not me warning you twice, it's just that important 🫢

The DBD::Excel module is a DBI driver. The module is based on these modules:

  • Spreadsheet::ParseExcel β€” reads Excel files πŸ“–
  • Spreadsheet::WriteExcel β€” writes Excel files ✍️
  • SQL::Statement β€” a simple SQL engine 🧠
  • DBI β€” Of course. :-) πŸ’€

This module assumes TABLE = Worksheet. The contents of the first row of each worksheet are used as column name. yes, first row = your column names, that's the vibe ✨

Adding that, this module accepts a temporary table definition in the "connect" method with the "xl_vtbl" option.

Example:

my %options = (
    xl_vtbl => { # define temporary tables here
        TESTV => { # temporary table name => options
            sheetName => 'TEST_V', # actual Excel sheet name
            ttlRow    => 5,
            startCol  => 1,
            colCnt    => 4,
            datRow    => 6,
            datLmt    => 4,
        }
    }
);
my $dbh = DBI->connect("DBI:Excel:file=dbdtest.xls", undef, undef, \%options);

For more information please refer to the file sample/tex.pl which is included in this distribution. go read it bestie, it's right there πŸ“š

πŸ¦‹ Metadata πŸ¦‹

The following attributes are handled by DBI itself and not by DBD::Excel, thus they all work like expected:

Active
ActiveKids
CachedKids
CompatMode             (Not used)
InactiveDestroy
Kids
PrintError
RaiseError
Warn                   (Not used)

The following DBI attributes are handled by DBD::Excel:

  • AutoCommit β€” Always on ⚑
  • ChopBlanks β€” Works βœ…
  • NUM_OF_FIELDS β€” Valid after "$sth->execute"
  • NUM_OF_PARAMS β€” Valid after "$sth->prepare"
  • NAME β€” Valid after "$sth->execute"; "undef" for Non-Select statements.
  • NULLABLE β€” Not really working, always returns an array ref of one's. Valid after "$sth->execute"; "undef" for Non-Select statements. 😭 she's doing her best

These attributes and methods are not supported:

bind_param_inout
CursorName
LongReadLen
LongTruncOk

Additional to the DBI attributes, you can use the following attributes:

  • 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.

🌈 Driver private methods 🌈

  • data_sources β€” The "data_sources" method returns a list of '*.xls' files of the current directory in the form "DBI:Excel:xl_dir=$dirname".

If you want to read the subdirectories of another directory, use

my($drh) = DBI->install_driver("Excel");
my(@list) = $drh->data_sources( { xl_dir => '/usr/local/xl_data' } );
  • list_tables β€” This method returns a list of sheet names contained in the "$dbh-"{file}>. Example:
my $dbh = DBI->connect("DBI:Excel:file=test.xls");
my @list = $dbh->func('list_tables');

⭐ TODO ⭐

  • More tests β€” First of all... πŸ‘€
  • Type and Format β€” The current version not support date/time and text formatting. πŸš«πŸ“…
  • Joins β€” The current version of the module works with single table SELECT's only, although the basic design of the SQL::Statement module allows joins and the likes.

πŸ’€ KNOWN BUGS πŸ’€

  • There are too many TODO things. So I can't determine what is BUG. :-) πŸ’… iconic honestly

πŸ‘‘ AUTHOR πŸ‘‘

Kawai Takanori (Hippo2000) originally created this module. Currently maintained by Alexander Becker. 🫢


πŸ”₯ SEE ALSO πŸ”₯

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.


and that's the whole page bestie πŸ’– this was DBD::Excel(3pm) from perl v5.38.2, dated 2024-02-18. slay, go parse some spreadsheets, ily πŸ¦‹βœ¨
πŸ“¦ where this page comes from