I use the script below, which uses the excellent Spreadsheet::ParseExcel package (available through ppm) on my web server to render Excel spreadsheets to my intranet. It does a much better job than MS-Office, because it produces clean HTML, and can be customised heavily to effectively use the spreadsheets as the database to drive customised web pages.
The parameters to the script are excelFile=xx.xls, where xx.xls resides in the c:/inetpub/wwwroot/ directory on an IIS server.
#!d:\perl\bin\perl.exe use strict; use Time::gmtime; use CGI qw(:standard); use Spreadsheet::ParseExcel; my $excelFile='c:/inetpub/wwwroot/' . param('excelFile'); my $title=$excelFile; my $oExcel = new Spreadsheet::ParseExcel; my $oBook = $oExcel->Parse($excelFile); my($iR, $iC, $oWkS, $oWkC); printHeader(); printBody(); sub printSpreadsheet() { my $startpage = 0; print "<h1>FILE :", $oBook->{File} , "<h1>\n"; for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) { $oWkS = $oBook->{Worksheet}[$iSheet]; if($oBook->{SheetCount} gt 1) { print h1($oWkS->{Name}); } print "<table border=0 cellpadding=1 width=100% "; print "BGCOLOR='#808080' width=100%>\n"; for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) + { print "<tr>\n"; for(my $iC = $oWkS->{MinCol} ; defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; $iC++) { $oWkC = $oWkS->{Cells}[$iR][$iC]; if($oWkC) { print "<td bgcolor=\'"; print $oExcel->ColorIdxToRGB($oWkC->{Format}->{Fil +l}[1]),"\'>\n"; if ($iR eq 0 or $iC eq 0) { print "<b>"; } if ($oWkC->Value ne '') { print toHtml($oWkC->Value), "\n"; } else { print " "; } if($iC == 2 && $iR gt 1) { print "</a>"; } print "</td>\n"; } else { print "<td bgcolor='#C9C7BA'> </td>\n"; } } print "</tr>\n"; } print "</table>\n"; } } ######################################################### sub printHeader { print "Content-type:text/html\n\n"; print "<html><head>\n"; print "<title>", $title, "</title>"; print "<LINK rel='stylesheet' type='text/css' "; print "href='http://localhost/styles.css'>\n"; print "<SCRIPT language=JavaScript>\n"; print " function linkURL(thisURL)\n"; print " { \n"; print " var re = / /g;\n"; print " var newThisURL = thisURL.replace(re, \"%20\"); \n"; print " window.location =newThisURL; \n"; print " }\n"; print "</SCRIPT>\n"; print "</head>\n"; print "<body bgcolor='#FFFFFF'>\n"; } ######################################################### sub printBody() { printSpreadsheet(); print "x</body>\n"; print "</html>\n"; } ######################################################### sub toHtml() { local ($_) = @_; s/&/&/g; s/>/>/g; s/</</g; # etc... return $_; }
In reply to Rendering Clean MS-Excel Spreadsheets to a Browser by emarsee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |