Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??


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


In reply to Re: csv2xls.pl by jmcnamara
in thread (code) text2xls.pl (was csv2xls.pl) by ybiC

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (12)
    As of 2015-07-31 15:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (279 votes), past polls