Click here to get back home

Converting the text output to excel via perl.

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Converting the text output to excel via perl. Sana 08-25-2008
Get Chitika Premium
Posted by Sana on August 25, 2008, 3:10 am
Please log in for more thread options


I have the following output which I want to convert into excel...Any
pointers how to achieve it via Spreadsheet::WriteExcel;

I am a beginer so pardon my lack of knowledge in perl.

lpar_name minmem desmem maxmem minpr despr maxpr
commuq21 2048 8192 12288 0.1 1.0 2.0
commuq20 2048 8192 12288 0.1 1.0 2.0
commuq23 2048 16384 40960 0.1 2.0 4.0
commud18 3072 40960 61440 0.2 2.0 5.0
commup03 2048 24576 30720 0.1 3.0 4.0
commup02 10240 32768 32768 1.0 4.0 8.0
commup01 10240 32768 32768 1.0 4.0 8.0

Regards
Sana

Posted by Grant on August 25, 2008, 4:51 am
Please log in for more thread options



>I have the following output which I want to convert into excel...Any
>pointers how to achieve it via Spreadsheet::WriteExcel;
>
>I am a beginer so pardon my lack of knowledge in perl.
>
>lpar_name minmem desmem maxmem minpr despr maxpr
>commuq21 2048 8192 12288 0.1 1.0 2.0
>commuq20 2048 8192 12288 0.1 1.0 2.0
>commuq23 2048 16384 40960 0.1 2.0 4.0
>commud18 3072 40960 61440 0.2 2.0 5.0
>commup03 2048 24576 30720 0.1 3.0 4.0
>commup02 10240 32768 32768 1.0 4.0 8.0
>commup01 10240 32768 32768 1.0 4.0 8.0

Crikey mate, I used to just export to a <tab> delimited file and excel
knows how to read them direct :)

Grant.
--
http://bugsplatter.id.au/

Posted by Mladen Gogala on August 25, 2008, 6:03 am
Please log in for more thread options


Grant wrote:

> Crikey mate,

Obviously, that darned stingray hasn't done its job....

> I used to just export to a <tab> delimited file and excel
> knows how to read them direct :)
>

There is, of course, Text::CSV module on CPAN...
http://search.cpan.org/~makamaka/Text-CSV-1.08/lib/Text/CSV.pm

--
http://mgogala.freehostia.com

Posted by A. Sinan Unur on August 25, 2008, 6:44 pm
Please log in for more thread options


e5a6b93e362a@z11g2000prl.googlegroups.com:

> I have the following output which I want to convert into excel...Any
> pointers how to achieve it via Spreadsheet::WriteExcel;
>
> I am a beginer so pardon my lack of knowledge in perl.

s/perl/Perl/

perl is the binary, Perl is the language.

Do you know any Perl? Can you put something together using the
documentation for the module Spreadsheet::WriteExcel?

The documentation is extremely clear and well written. Examples abound.
Just the synopsis is enough to solve this problem if you can program in
any language.

So, please read the posting guidelines for this group, then come up with
your best effort at implementing a solution. You will be much more
likely to get good help if you are willing to do that.

To provide some incentive for you to learn how to fish, here is a
template:

#!/usr/bin/perl

use strict;
use warnings;

use Spreadsheet::WriteExcel;

my $book = # add code to create a new workbook
my $sheet = # add code to add a new sheet to $book

while ( my $line = <DATA> ) {
$line =~ s/^\s+//;
$line =~ s/\s+$//;
last unless length $line;

my $row = [ split /\s+/, $line ];
# Add code to write a new row to $sheet
# the special variable $. would be useful
# here. See perldoc perlvar.
}

# add code to close $book

__DATA__
lpar_name minmem desmem maxmem minpr despr maxpr
commuq21 2048 8192 12288 0.1 1.0 2.0
commuq20 2048 8192 12288 0.1 1.0 2.0
commuq23 2048 16384 40960 0.1 2.0 4.0
commud18 3072 40960 61440 0.2 2.0 5.0
commup03 2048 24576 30720 0.1 3.0 4.0
commup02 10240 32768 32768 1.0 4.0 8.0
commup01 10240 32768 32768 1.0 4.0 8.0



--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by John W. Krahn on August 26, 2008, 12:09 am
Please log in for more thread options


A. Sinan Unur wrote:
>
> To provide some incentive for you to learn how to fish, here is a
> template:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Spreadsheet::WriteExcel;
>
> my $book = # add code to create a new workbook
> my $sheet = # add code to add a new sheet to $book
>
> while ( my $line = <DATA> ) {
> $line =~ s/^\s+//;
> $line =~ s/\s+$//;
> last unless length $line;
>
> my $row = [ split /\s+/, $line ];

Or more simply:

while ( my $line = <DATA> ) {
last unless $line =~ /\S/;

my $row = [ split ' ', $line ];

> # Add code to write a new row to $sheet
> # the special variable $. would be useful
> # here. See perldoc perlvar.
> }


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Similar ThreadsPosted
converting vertical text to horizontal text February 1, 2005, 3:16 pm
Need help converting unix text to windows text March 22, 2005, 12:35 am
Converting Diff Output to XML? June 26, 2007, 10:57 am
perl TK related (manupulating the output text area) June 2, 2006, 4:53 am
Converting multiple spaces for 3 col text? November 6, 2004, 9:33 pm
replacing text at the beginning of a file in perl and appending to that output July 20, 2005, 8:33 am
dump text to excel and CPAN search August 15, 2005, 12:29 pm
adding an excel worksheet to a generetad excel file via perl April 17, 2007, 8:38 am
Help: Output specific text from a starter January 3, 2009, 9:31 am
OLE & Excel - Opening causes Excel.exe to hang around April 21, 2005, 1:20 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap