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

pnuts
  • 58,317
  • 11
  • 87
  • 139
Hiren Patel
  • 59
  • 1
  • 3
  • 9
  • 1
    Start by reading the PHPExcel documentation and looking at some of the example files in the /Examples folder – Mark Baker Sep 18 '14 at 12:46

2 Answers2

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);
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • // 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) – Hiren Patel Sep 19 '14 at 05:23
  • 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](https://github.com/PHPOffice/PHPExcel/issues/384)) has been fixed in PHPExcel – Mark Baker Sep 19 '14 at 07:02
  • 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 – Hiren Patel Sep 19 '14 at 07:23
  • 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 – Mark Baker Sep 19 '14 at 07:25
  • ok Mark Baker and my another question is my HTML code is available in php file do you supported $inputFileType='PHP'? – Hiren Patel Sep 19 '14 at 07:28
  • No, files with an extension of PHP are not any valid spreadsheet format.... PHP is a programming language. A PHP script can generate output that is a valid spreadsheet format, but being able to accept an input type of PHP containing any arbitrary php code and automagically convert it to something that resembles a spreadsheet is an impossible exercise – Mark Baker Sep 19 '14 at 07:32
  • If your PHP generates an HTML table in an html file, then PHPExcel can read that file as a spreadsheet table.... alternatively modify your PHP code so that it uses PHPExcel to create an Excel file directly instead of generating HTML – Mark Baker Sep 19 '14 at 07:34
  • Why Reading HTML if it can't support css and pictures? – Charaf JRA Nov 24 '15 at 17:19
  • @Charafjra - BECAUSE THAT'S ALL THAT I'VE WRITTEN IT TO DO.... it's to support the basic "fake" Excel files that some scripts generate that are little more than an html table.... if you want to complain, then spend several hours a day of your own time over ten years developing/supporting open source software without recompense; if you want to be constructive, submit a PR for the HTML Reader that does support css and pictures...... also learn that asking a question on SO shouldn't be done by asking it in a comment to an answer to somebody else's question – Mark Baker Nov 24 '15 at 17:23
  • @MarkBaker I'm sorry, no offense, my question was to understand HTML Reader's role, because when I read the introduction of your project in Github, it says that it support reading HTML, it should be clearer so that users don't spend too much time.About commenting, it's not an answer neither, better commenting than answering.And thank you for all your Opensource contributions over this 10 years, you really deserve a medal :) Good evening – Charaf JRA Nov 24 '15 at 17:40
  • 1
    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 – Mark Baker Nov 24 '15 at 17:43
  • I know it will take too much time, it should be done by the community, that's the beauty of OpenSource.Thank you Mark – Charaf JRA Nov 24 '15 at 17:50
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" .

user3493407
  • 37
  • 1
  • 8
  • Read the question, he wants to use PHPExcel – iswinky Sep 18 '14 at 12:57
  • // 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) – Hiren Patel Sep 19 '14 at 05:23