#!/usr/bin/perl -s # tsv2xls - filter tab-separated text into an Excel worksheet # Steve Kinzler, kinzler@cs.indiana.edu, May 03 # http://www.cs.indiana.edu/~kinzler/home.html#unix use Spreadsheet::WriteExcel; die "usage: $0 [ -t ] [ -T ] [ infile | - ] [ outfile ] -t highlights the first row as titles -T highlights the second row as titles\n" if $h; $in = (@ARGV) ? shift : '-'; $book = Spreadsheet::WriteExcel->new(@ARGV ? $ARGV[0] : '-'); $sheet = $book->addworksheet(); $sheet->keep_leading_zeros(); if ($t || $T) { $fmt = $book->addformat(); $fmt->set_bold(); $fmt->set_align('center'); $fmt->set_border(); $fmt->set_bg_color('tan'); $sheet->set_row(0, undef, $fmt) if $t; $sheet->set_row(1, undef, $fmt) if $T; } open(IN, "< $in") || die "$0: cannot open $in ($!)\n"; $r = 0; while () { chomp; @_ = split("\t", $_); $c = 0; foreach (@_) { (/^()?$/) ? $sheet->write_blank($r, $c++, undef) : $sheet->write( $r, $c++, $_); } $r++; } close IN; $book->close();