And if I'd looked just a wee bit further than the pod, I'd have found ~/Spreadsheet/WriteExcel/examples/csv2xls.pl which does this exact same thing.
Yes, but yours is nicer. ;-) In fact if you don't mind I'll include it in the
Spreadsheet::WriteExcel distro. Since your version deals with generic separators you could re-target it and call it text2xls.
Just a few notes:
Parsing CSV is never as easy as it seems, therefore, for more general applications it is worth considering
Text::CSV_XS or
Text::CSV. If the stated purpose is to split on a single character then your method is fine.
# Prettify row as header.
Prettifying the first row is a good idea. Unfortunately, it won't work like this because
set_row() defines the default format for cells written by Excel and not for cells written by WriteExcel. This is easy to fix.
# Unfortunately no support for "freeze pane"
Freeze panes will be in the next version. It is a feature that a *lot* of people have requested.
USAGE:
For anything more than a single line of usage the
POD::Usage module is worth considering. This keeps your POD and your usage synchronised. It is also one of the core modules. I tend to use it in any program where I use Getopt::Long. It is a useful module and a clever idea.
Todo: binmode(FH) on xls outfile for cross-platform support.
This isn't required.
Spreadsheet::WriteExcel will take care of
binmode() for you. It only applies if you are creating a new file based on a filehandle as opposed to a filename.
A useful feature would be an option to split the input file into pages based on ^L, or some other delimiter, and put each page on a new worksheet. This is something that I wanted to add it to the
csv2xls.pl example but I didn't have time.
John.
--
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.