Skip to content

Instantly share code, notes, and snippets.

@readbio
Created September 21, 2016 18:58
Show Gist options
  • Save readbio/208e06a5fadfeade6921c68aa01ce119 to your computer and use it in GitHub Desktop.
Save readbio/208e06a5fadfeade6921c68aa01ce119 to your computer and use it in GitHub Desktop.
#!/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]);
}
}
@readbio
Copy link
Author

readbio commented Sep 21, 2016

Use cpanm to install Excel::Writer::XLSX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment