csv to xls conversion using perl commands

Posted on 2008-06-16
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.
Question by:theology99
  • 7
  • 3
  • 2
  • +1
LVL 84

Expert Comment

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

Author Comment

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.


LVL 84

Expert Comment

ID: 21799996
what should the xls file contain?
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 84

Expert Comment

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

Author Comment

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

Author Comment

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

Author Comment

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.

Author Comment

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

Expert Comment

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.

Author Comment

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.

LVL 39

Accepted Solution

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.

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;
my $format_yellow=$workbook->add_format;
my $format_blue=$workbook->add_format;
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++) {
		print "Writing ($row, $col)\n";

Open in new window


Author Closing Comment

ID: 31467853

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

9 Experts available now in Live!

Get 1:1 Help Now