Solved

csv to xls conversion using perl commands

Posted on 2008-06-16
13
2,658 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

19 Experts available now in Live!

Get 1:1 Help Now