I'm looking for a way to read an excel file (xls format, but could probably use xlsx if necessary), and convert that file into an html table, preserving the rich text in the cells, cell borders, as well as the hyperlinks.
I've looked at https://code.google.com/p/php-excel-reader2/, which looks pretty good except some borders are missed and hyperlink targets have missing letter at end of filename (weird). I could probably debug these if I have to, but another problem with this is that this code base isn't supported any more. See http://www.steeplechasers.org/racecalendar-php-excel.php for example (spreadsheet is at http://www.steeplechasers.org/racecalendar.xls ).
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("racecalendar.xls");
?>
<html>
<head>
<style>
table.excel {
border-style:ridge;
border-width:1;
border-collapse:collapse;
font-family:sans-serif;
font-size:12px;
}
table.excel thead th, table.excel tbody th {
background:#CCCCCC;
border-style:ridge;
border-width:1;
text-align: center;
vertical-align:bottom;
}
table.excel tbody th {
text-align:center;
width:20px;
}
table.excel tbody td {
vertical-align:bottom;
}
table.excel tbody td {
padding: 0 3px;
border: 1px solid #EEEEEE;
}
</style>
</head>
<body>
<?php echo $data->dump(true,true); ?>
</body>
</html>
I also looked at https://github.com/PHPOffice/PHPExcel, which seems like it should be able to do this somehow, but using simple generateSheetData, borders rich text and hyperlinks don't seem to be preserved, and I'm having trouble groking the docs to see how to copy these attributes into html. See http://www.steeplechasers.org/racecalendar-PHPExcel.php for example (same input file).
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'PHPExcel/Classes/PHPExcel.php';
$filename = 'racecalendar.xls';
//$filetype = PHPExcel_IOFactory::identify($filename);
$reader = PHPExcel_IOFactory::createReaderForFile($filename);
$reader->setReadDataOnly(true);
$excel = $reader->load($filename);
$writer = PHPExcel_IOFactory::createWriter($excel, "HTML");
?>
<html>
<head>
</head>
<style>
<?php
echo $writer->generateStyles(false);
?>
</style>
<body>
<?php
echo $writer->generateSheetData();
?>
</body>
</html>
Convert HTML to Excel Rich Text and vice versa seems to indicate this isn't a feature of PHPExcel yet.
PHPExcel - Preserve rich text format on import didn't answer the question at all, as far as I could tell.
Is there another way to do this directly, or some way to do this with PHPExcel?
NOTE: I would actually like to iterate through the cells because I want to add a column to the html table as I go -- I used code to dump the whole spreadsheet as simple examples of the package behaviors, and this is as far as I have gotten in my investigation.