Hi monks,

I've data in an Excel format and I would like to feed that data to mysql. I just discovered Spreadsheet::ParseExcel and found it to be really cool.

What I intend to do is to parse the excel file using ParseExcel and then have the perl script write the necessary sql statements into a source file. For instance, let's say I've two rows of data from Excel as follows:

id joke created owner 1 joke one 2004-04-12 john 2 joke two 2004-04-11 nick
The output from the perl script (using ParseExcel) will be saved to a insert source file and it will look something like:
INSERT INTO JOKES VALUES('1', 'joke one', '2004-04-12', 'john'); INSERT INTO JOKES VALUES('2', 'joke two', '2004-04-11', 'nick');
I will then use mysql command 'source name_of_file' to insert the data into a table.

I suppose I could have the script connect to the database and directly insert the data to the relevant table, thereby bypassing the step to create a mysql source file.

Am I on the right track? Is there perhaps a more direct conversion path from Excel to mysql?

Cheers and many thanks in advance :)

Update: Great thanks to all for your solutions and ideas!


In reply to From excel to mysql... by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.