-4

I want to read HTML table data from HTML page (without using of data base) and Export into Excel file . I am using this Javascript cede but it is not working. Please Suggest me, I am 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;
    }
}

}

user3040433
  • 85
  • 2
  • 4
  • i didn't get correct answer. – user3040433 Jan 31 '14 at 15:33
  • 5
    That doesn't mean you re-ask the same question AND post it on P.SE, where it doesn't belong. I have a strong feeling you just grabbed this code somewhere and do not have any idea what it actually is doing - meaning you will never solve this. – patricksweeney Jan 31 '14 at 15:39
  • 1
    I hear you should parse HTML with regexps... – Jimmy Hoffa Jan 31 '14 at 16:42
  • Try to create a simple data structure (e.g. CSV) that you alert/console.log out and examine the output. This will help you to troubleshoot your problem. – Juergen Riemer Jan 31 '14 at 16:43
  • 1) No PHP is present or mentioned. 2) Most of this is just automation code for ActiveX in Internet Explorer, and is not in any way related to databases. 3) You'll want to refer to original documentation, such as from Microsoft: http://msdn.microsoft.com/en-us/library/7sw4ddf8%28v=vs.94%29.aspx You'll need something that works, even in a hello world context, then one might be able to get help from there. – BrianH Jan 31 '14 at 20:10

1 Answers1

0

Pasre_html.php

 <?php 
  include 'simple_html_dom.php';//You have to DOWNLOAD THIS FILE


  //IF YOU WANT HTML FILE FROM DATABASE THIS WILL HELP YOU
   //$ftch_file=mysql_query("SELECT * FROM tb_htmlfile WHERE 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 YOU WANT TO PARSE DIV $cells = $html->find('DIV');
    $i=0;
     foreach($cells as $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]; 
  ?>
user3040433
  • 85
  • 2
  • 4