Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: converting a csv file to fix width text

by graff (Chancellor)
on Oct 31, 2015 at 05:00 UTC ( [id://1146554]=note: print w/replies, xml ) Need Help??


in reply to converting a csv file to fix width text

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

  • Comment on Re: converting a csv file to fix width text

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146554]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found