开发者

Problems exporting HTML table to Excel

I have a table in which one td element has an anchor tag inside it for a number.

<td><a href="">213123</a></td>

I am exporting my table data elements to Excel. When the table is exported it is a开发者_高级运维lso printing the anchor tag along with the number. Is there a way that I could avoid the anchor tag in Excel sheet and just display the number in the column?

I am using the following code:

function export_to_excel( ptablebody) {

    str="";
    var ExcelApp = new ActiveXObject("Excel.Application");
    var ExcelSheet = new ActiveXObject("Excel.Sheet");
    ExcelSheet.Application.Visible = true;

    var myTableHead = document.getElementById(ptablebody);
    var rowCount = myTableHead.rows.length;

    var colCount = myTableHead.getElementsByTagName("tr")[0].getElementsByTagName("td").length; 

    for(var i=0; i<rowCount; i++) {   
        for(var j=0; j<colCount; j++) {           
            str= myTableHead.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerHTML;
            ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = str;
        }
    }
}


I think you want innerText (or on firefox textContent) instead of innerHtml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜