Solved

csv to xls conversion using perl commands

Posted on 2008-06-16
13
2,663 Views
Last Modified: 2010-04-21
I hava a csv file on my debian machine, now I want to convert this csv file in to xls using the perl script.
0
Comment
Question by:theology99
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21799775
where in the xls file do you want to put the fields from the csv file?
0
 

Author Comment

by:theology99
ID: 21799893
I have the csv file in my temp directory, I want that I can convert the csv format to xls so that I can work further on this xls sheet to color my items.
As this is not possible in them csv format.



Thanks



0
 
LVL 84

Expert Comment

by:ozo
ID: 21799996
what should the xls file contain?
0
 
LVL 84

Expert Comment

by:ozo
ID: 21800011
#you could
use Spreadsheet::WriteExcel;
#among others
0
 

Author Comment

by:theology99
ID: 21800052
the whole conatins of the csv file.

xls is the exceel sheet..

For example:

I have csv as hello.csv which contains rows and columns , hich have some data as:

test1  test2  test3  test4
aa      33       44     55
bb      34       45     45


only simple conversion fron csv fromat to xls fromat.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 21800121
You don't have to use a programming language for this. If you install OpenOffice 2.0 on debian, it should let you load a csv file and export it ot xls format
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:theology99
ID: 21800315
But I am using the text mode not using the graphical mode
how it can be possible?
0
 

Author Comment

by:theology99
ID: 21800518
I have installed the apt-get install gnumeric xalan following.
But that also not helped me.

For an example I am attaching a csv with this .
I need a program/command on the debian (in text mode) that can convert this csv to xls
and then open the xls and color the codes 55, 44 etc with the diff colors.


Kindly help.
0
 

Author Comment

by:theology99
ID: 21800523
test1      44
test2      55
test3      44
test4      66
test5      44
test6      55
0
 
LVL 39

Expert Comment

by:Adam314
ID: 21803205
Excel can open the csv file without making any changes to it.  Is there anything the perl script needs to do other than convert from csv to xls?  If not, don't bother converting, just have excel open the csv file.
0
 

Author Comment

by:theology99
ID: 21809784
Yes , it is.
I want to color the csv file and it is not possible thats why I want to convert csv to xls and then I color it later on.

Thats why my first concern is to convert sv to xls and all this need to be done by perl scripting on the debian box.


0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 21813996
It will be easier to read the csv to create the xls and apply the color at one time, rather than as two seperate steps.

#!/usr/bin/perl

use strict;

use warnings;

use Spreadsheet::WriteExcel;
 

my $workbook  = Spreadsheet::WriteExcel->new('testcolor.xls');

my $worksheet = $workbook->add_worksheet();
 

my $format_red=$workbook->add_format;

$format_red->set_color('red');
 

my $format_yellow=$workbook->add_format;

$format_yellow->set_color('yellow');
 

my $format_blue=$workbook->add_format;

$format_blue->set_color('blue');
 
 

my $row=0;

open(CSV, "<file.csv") or die "Could not open CSV: $!\n";

while(<CSV>) {

	my @f=split/,/;

	my $thisformat;

	$thisformat=$format_red if $f[2]==35;

	$thisformat=$format_yellow if $f[2]==45;

	$thisformat=$format_blue if $f[2]==20;

	for(my $col=0; $col<=$#f; $col++) {

		$worksheet->write($row,$col,$f[$col],$thisformat);

		print "Writing ($row, $col)\n";

	}

	$row++;

}

close(CSV);

Open in new window

0
 

Author Closing Comment

by:theology99
ID: 31467853
Thanka.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now