vkp has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am writing a code to convert EXCEL file to text file. I am using CPAN module parse_excel for this. I have done with my code.But here is a problem, the data in each cell of excel file could have different characters. So for column wise the words are not aligned with each other. for example my text file may look as:

boy girl father mother sis bro
Here, i have introduced 4 spaces between each word of each row. but i need result in this form
boy girl father mother sis bro
Each word may get aligned with other words Regards

Replies are listed 'Best First'.
Re: Need help to convert excel file to text file
by 2teez (Vicar) on Jun 21, 2013 at 07:11 UTC

    So for column wise the words are not aligned with each other..
    You could check Text::Table like so:

    use warnings; use strict; use Text::Table; my $table = Text::Table->new("Person1 ", " Person2"); $table->load( ['boy ',' girl'], ['father ',' mother'], ['sister ',' brother'], ); print $table;
    Person1 Person2 boy girl father mother sister brother
    Or Perl6::Form

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: Need help to convert excel file to text file
by kcott (Archbishop) on Jun 21, 2013 at 07:15 UTC

    G'day vkp

    You can create formatted strings with sprintf and output formatted strings with printf.

    -- Ken

Re: Need help to convert excel file to text file
by hdb (Monsignor) on Jun 21, 2013 at 06:51 UTC

    perlform might be a solution for you. See the examples therein.

Re: Need help to convert excel file to text file
by locked_user sundialsvc4 (Abbot) on Jun 21, 2013 at 12:58 UTC

    Often what is done is to generate HTML, then use a browser to look at the results.   Another way to do it is to generate a PDF.   Basically, in both cases you are pushing the work of “pretty printing” off to another application.

    There is also a very limited ability to use \t tab-characters in certain forms of printed output.   These might be interpreted correctly (by whatever ultimately prints the file), to create a crude but effective form of formatting.

    Quite seriously... maybe you should just let Excel do it.