Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: converting a csv file to fix width textby graff (Chancellor) |
on Oct 31, 2015 at 05:00 UTC ( [id://1146554]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|