Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
XTRAIL
/
andre
/
PERL
:
csv2htm.pl
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
#!c:/perl/bin/perl.exe # #____________________________________________________________________ # # PROJ: csv2htm.pl # DATE: May 1999 # $ver = "0.9"; # # # AUTH: Marcus Kazmierczak # marcus@mkaz.com # http://www.blazonry.com/perl/ # # DESC: Simple CSV to HTML converter # Converts Comma Delimited text (CSV) to # an HTML file. Used for converting an excel # spreadsheet saved as CSV to an HTML table. # # USAGE: # # csv2htm.pl <input.csv> <output.htm> #____________________________________________________________________ # delimiter # change this to \t for tab delimited, or # any other characters or string for that delimination $delim = ","; printInfo(); $infile = $ARGV[0]; $outfile = $ARGV[1]; if ((!$infile) || (!$outfile)) { printUsage(); } $fstline=1; open (OUT, ">$outfile") || die ("Error Opening $outfile \n$!\n"); printHeader(); open (IN, "<$infile") || die ("Error Opening $infile \n$!\n"); while ($line = <IN>) { chomp($line); if ($fstline) { print OUT "<TR BGCOLOR=\"#EEEEEE\"><TH>"; $line =~ s/$delim/<\/TH><TH VALIGN=TOP>/g; print OUT "$line"; print OUT "</TH></TR>\n"; $fstline = 0; } else { print OUT "<TR><TD>"; $line =~ s/$delim/<\/TD><TD VALIGN=TOP>/g; print OUT "$line"; print OUT "</TD></TR>\n"; } } close (IN); printFooter(); close(OUT); print "$infile converted to $outfile\n\n"; ##################################################################### ### SUB-ROUTINES # ##################################################################### #____________________________________________________________________ # # SUB: printHeader() # # DESC: prints out HTML header to output file #____________________________________________________________________ sub printHeader { print OUT "<HTML>\n<HEAD>\n"; print OUT " <TITLE>$infile</TITLE>\n"; print OUT "<!-- Generated by csv2htm.pl $ver\n"; print OUT " Marcus Kazmierczak, marcus\@mkaz.com -->\n"; print OUT "</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\">\n\n"; print OUT "<TABLE CELLPADDING=4 CELLSPACING=0 BORDER=1>\n"; } #____________________________________________________________________ # # SUB: printFooter() # # DESC: prints out HTML Footer to output file #____________________________________________________________________ sub printFooter { print OUT "</TABLE>\n"; print OUT "</BODY>\n</HTML>"; } #____________________________________________________________________ # # SUB: printInfo() # # DESC: prints out script info #____________________________________________________________________ sub printInfo { print "csv2htm.pl ver $ver\n"; print "Marcus Kazmierczak, marcus\@mkaz.com\n\n"; } #____________________________________________________________________ #____________________________________________________________________ # # SUB: printUsage() # # DESC: prints out script usage #____________________________________________________________________ sub printUsage { print "csv2htm <input.csv> <output.htm>\n"; exit(1); } #____________________________________________________________________