0

我需要在 PHPExcel 中将 html 文件(test.html)转换为 excel

myhtml 文件 text.html 它是保存 test.php 但包含 html

请想法如何在此实施

4

2 回答 2

7

您可以简单地阅读提供的文档,但是:

$inputFileType = 'HTML';
$inputFileName = './myHtmlFile.html';
$outputFileType = 'Excel2007';
$outputFileName = './myExcelFile.xlsx';

$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objPHPExcelReader->load($inputFileName);

$objPHPExcelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$outputFileType);
$objPHPExcel = $objPHPExcelWriter->save($outputFileName);
于 2014-09-18T13:03:42.160 回答
0

好的,请按照此步骤操作。创建一个 php 文件并在其中粘贴此代码

<?php
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment;Filename=document_name.xls");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
... echo Your Html data...
echo "</body>";
echo "</html>";
?>

代替您的 html 数据,在您的 test.html 中回显 html 部分。然后运行这个 php 文件,你会得到名为 "document_name.xls" 的 MS excel 文件。

于 2014-09-18T12:30:58.957 回答