Exchanging Data Between MySQL and Microsoft Excel
Problem
You want to exchange information between MySQL and Excel.
Solution
Use utilities such as DBTools or MySQLFront. Or use Perl modules that read and write Excel spreadsheet files to construct your own data transfer utilities.
Discussion
One way to transfer Excel files into MySQL is to use the DBTools or MySQLFront utilities that were discussed in Recipe 10.39 for working with Access files. Both programs know how to read Excel files as well. But both are Windows-specific; for a more cross-platform solution that works for both Unix and Windows, you can read and write Excel spreadsheets from within Perl scripts by installing a few modules:
Spreadsheet::ParseExcel::Simple
provides an easy-to-use interface for reading Excel spreadsheets.Spreadsheet::WriteExcel::Simple
allows you to create files in Excel spreadsheet format.
These modules are available from the Perl CPAN. (They’re actually frontends to other modules, which you’ll also need to install as prerequisites.) After installing the modules, use these commands to read their documentation:
%perldoc Spreadsheet::ParseExcel::Simple
%perldoc Spreadsheet::WriteExcel::Simple
These modules make it relatively easy to write a couple of short scripts (shown below) for converting spreadsheets to and from tab-delimited file format. Combined with techniques for importing and exporting data into and out of MySQL, these scripts can help you move spreadsheet contents to MySQL tables and vice ...
Get MySQL Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.