Created
September 21, 2016 18:58
-
-
Save readbio/208e06a5fadfeade6921c68aa01ce119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
################################################## | |
#This script is to convert tab-delimited file to # | |
#Exel sheets. # | |
################################################## | |
use Excel::Writer::XLSX; | |
my ($tab, $out) = @ARGV; | |
die usage() unless @ARGV == 2; | |
sub usage{ | |
my $die =<<DIE; | |
perl *.pl <Input file: tab-delemited file> <output file in XLSX file> | |
DIE | |
} | |
my $workbook = Excel::Writer::XLSX->new($out); | |
my $worksheet = $workbook->add_worksheet(); | |
my $row = 0; | |
open TAB, $tab or die "$!"; | |
while(<TAB>){ | |
chomp; | |
my @ele = split(/\t/); | |
&write_xlsx($worksheet, $row, @ele); | |
++$row; | |
} | |
sub write_xlsx{ | |
my ($worksheet, $tem_row, @ele) = @_; | |
for(my $i = 0; $i < @ele; ++$i){ | |
$worksheet->write( $tem_row, $i, $ele[$i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use cpanm to install Excel::Writer::XLSX.