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 "&nbsp;"; } if($iC == 2 && $iR gt 1) { print "</a>"; } print "</td>\n"; } else { print "<td bgcolor='#C9C7BA'>&nbsp;</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/&/&amp;/g; s/>/&gt;/g; s/</&lt;/g; # etc... return $_; }

In reply to Rendering Clean MS-Excel Spreadsheets to a Browser by emarsee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.