In order to read from an Excel spreadsheet, you need an appropriate CPAN module (such as Spreadsheet::Read suggested above, or Spreadsheet::ParseExcel, Spreadsheet::XLSX, etc.

Once you have that part working, if you really need fixed-width text output, you'll want to loop over the rows and keep track of the longest string length in each column. Then, print each row using printf or pack.

I'm more familiar with printf, so I think it's easier; the full documentation is actually found under sprintf - it let's you control column width, left- vs. right-justification within the column, number of digits to the right of the decimal for floating-point numbers, and so on. Once you get the hang of it, you can do anything.

But I have to ask: what purpose will be served by having fixed-witdth text output? If it's for human readability, that's a good-enough reason, but if it's just to allow some other program to do something with data from Excel, there's probably a better way...


In reply to Re: converting a csv file to fix width text by graff
in thread converting a csv file to fix width text by jazzlover

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.