javascript - How to parse data from HTML and export in Excel in PHP -
this question exact duplicate of:
i want read html table data html page (without using of data base) , export excel file . using javascript cede not working. please suggest me, new here.
function write_to_excel() { str=""; var mytable = document.getelementsbytagname("table")[0]; var rowcount = mytable.rows.length; var colcount = mytable.getelementsbytagname("tr")[0].getelementsbytagname("td").length; var excelapp = new activexobject("excel.application"); var excelsheet = new activexobject("excel.sheet"); excelsheet.application.visible = true; for(var i=0; i<rowcount; i++) { for(var j=0; j<colcount; j++) { str= mytable.getelementsbytagname("tr")[i].getelementsbytagname("td")[j].innerhtml; excelsheet.activesheet.cells(i+1,j+1).value = str; } }
}
pasre_html.php
<?php include 'simple_html_dom.php';//you have download file //if want html file database //$ftch_file=mysql_query("select * tb_htmlfile status=1"); //while($ftch_file_row=mysql_fetch_array($ftch_file)) //{ //$inputfile='html_file/'. $ftch_file_row['file_name']; $inputfile='file.html'; $html = file_get_html($inputfile); //} $cells = $html->find('td');//if want parse div $cells = $html->find('div'); $i=0; foreach($cells $cell) { // $xyz = $cell->plaintext . "#"; $var[$i]=$cell->plaintext; $i++; /*$he=ereg_replace("([0-9]+)", "2000", $xyz);*/ //print_r(explode("#",$xyz)); } echo $var[$i]; //or echo $var[1]; $var[2]; ?>
Comments
Post a Comment