-1

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.

JS:

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;
        }
    }
}
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
user3040433
  • 85
  • 2
  • 4
  • 1
    If you already have a html table, you can just adjust the headers to [excel](http://stackoverflow.com/questions/9856518/php-excel-header) type and download it as xls document. – Peon Jan 31 '14 at 07:11
  • If you want to generate a more complex Excel document by php you might wanna check [PHPExcel](http://phpexcel.codeplex.com/) this library. – Madcoe Jan 31 '14 at 07:15
  • -1, if you want to get help on this site, please learn how to write precise failure descriptions, "is not working" is quite the opposite. – Doc Brown Jan 31 '14 at 17:48

1 Answers1

0

From PHP :

$objReader = PHPExcel_IOFactory::createReader('HTML');
$objPHPExcel = $objReader->load("myHtmlFile.html");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("myExcelFile.xlsx");
Ashish Kumar Saxena
  • 4,400
  • 8
  • 27
  • 48