导出到excel时,html表的div样式不会出现在excel中 [英] Div style of html table are not appearing in excel when exported to excel

查看:489
本文介绍了导出到excel时,html表的div样式不会出现在excel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML来源:

HTML SOURCE:

<html id="anil" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

    <script type="text/javascript" >

    function exportToExcel() {

            //copy innerHTML of YourTable to strCopy Variable.
         debugger;
            var strCopy = document.getElementById("anil").innerHTML ;


            // clickExcel

            //getElementById("Bdy1").innerHTML;
            //copy strCopy to clipboardData, this

            window.clipboardData.setData("Text", strCopy);

            var objExcel = new ActiveXObject("Excel.Application");

            objExcel.visible = true;

            var objWorkbook = objExcel.Workbooks.Add;

            var objWorksheet = objWorkbook.Worksheets(1);
             objWorksheet.Paste;

    }
    </script>

    <style type="text/css">

    div.each-element{
    border:2px solid red;
    text-align:center;
    font-family:'segoe ui';
    margin:2%;
    padding:1%;
}

  </style>


</head>
<body>
    <form id="form1" runat="server">
    <div id='parent'>
<table>
<tr>
<td>
<div>
    <div id='child1' class='each-element'>Child 1</div>
    <div id='child2' class='each-element'>Child 2</div>
    <div id='child3' class='each-element'>Child 3</div>
    </div>
    </td>
    </tr>
    </table>
</div>
 <input id="clickExcel" type="button" style="height:35px;width:189px" value="BtnExport"  onclick="javascript:exportToExcel();" onclick="return clickExcel_onclick()" />
    </form>
</body>
</html>

推荐答案

这篇关于导出到excel时,html表的div样式不会出现在excel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆