[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


csv to xls conversion using perl commands

Posted on 2008-06-16
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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

650 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