0

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

1
  • 1
    Start by reading the PHPExcel documentation and looking at some of the example files in the /Examples folder Commented Sep 18, 2014 at 12:46

2 Answers 2

7

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);
Sign up to request clarification or add additional context in comments.

12 Comments

// Read the contents of the file into PHPExcel Reader class $reader = new PHPExcel_Reader_HTML(); $objPHPExcel = $reader->load('/var/www/html/edusec_temp/bapucollege/protected/views/report/test.php'); Generate this error : in this line it shows me an error like : " DOMDocument::loadHTMLFile() expects exactly 1 parameter, 2 given " /var/www/html/edusec_temp/demo/protected/extensions/phpexcel/vendor/Classes/PHPExcel/Reader/HTML.php(427)
Either upgrade your PHP to a recent version (5.4 or 5.5) or make sure that you have the latest develop code from github, because that error (Work Item GH-384) has been fixed in PHPExcel
yes i am download latest PHPExcel code in fithub and my php version is 5.3.10 and my another question is input file type is php supported? because my html code is include in php file
If you have the latest github develop branch code then line 427 of Classes/PHPE‌​xcel/Reader/HTML.php should be if ((version_compare(PHP_VERSION, '5.4.0') >= 0) && defined(LIBXML_DTDLOAD)) {.... you'll only get the error message that you've quoted if you're not running the latest github develop branch code
It only supports the basic HTML markup, and even then, only simple elements; CSS isn't HTML, and note that most web browsers don't fully support HTML either..... but if I detail every single thing that is and isn't supported by PHPExcel, I'd never have time to work on the actual codebase
|
0

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

2 Comments

Read the question, he wants to use PHPExcel
// Read the contents of the file into PHPExcel Reader class $reader = new PHPExcel_Reader_HTML(); $objPHPExcel = $reader->load('/var/www/html/edusec_temp/demo/protected/views/report/test.php'); Generate this error : in this line it shows me an error like : " DOMDocument::loadHTMLFile() expects exactly 1 parameter, 2 given " /var/www/html/edusec_temp/demo/protected/extensions/phpexcel/vendor/Classes/PHPExcel/Reader/HTML.php(427)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.