Hiren Patel
Hiren Patel

Reputation: 59

Convert HTML file to Excel using PHPExcel

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

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

please idea how to implement in this

Upvotes: 0

Views: 25174

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

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

Upvotes: 7

user3493407
user3493407

Reputation: 37

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

<?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" .

Upvotes: 0

Related Questions