php 使用 PHPExcel 将 HTML 文件转换为 Excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25912440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:02:31  来源:igfitidea点击:

Convert HTML file to Excel using PHPExcel

phpphpexcelphpexcelreader

提问by Hiren Patel

I have required to convert html file (test.html) to excel in PHPExcel

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

myhtml file text.html it is save test.php but containt of html

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

please idea how to implement in this

请知道如何在此实施

回答by Mark Baker

You could simply read the documentation provided, but:

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

$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);

回答by user3493407

ok please follow this step. create a php file and in that paste this code

好的,请按照此步骤操作。创建一个 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>";
?>

in the place of your html data echo the html part in your test.html. then run this php file you will get MS excel file named "document_name.xls" .

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