?
Solved

csv to xls conversion using perl commands

Posted on 2008-06-16
13
Medium Priority
?
2,687 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 85

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 85

Expert Comment

by:ozo
ID: 21799996
what should the xls file contain?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans
Suggested Courses

862 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