LODOP导出excel的页眉页脚

Excel中的页眉页脚的设置方法:(测试用的是exce2016版)
菜单栏的页面布局——页面设置——页眉/页脚标签页,里面可以设置,具体可参考本博客下方的图示。
该页眉页脚不会显示在excel的表格界面里,在打印预览和打印的时候会看到添加的页眉页脚。

LODOP中导出excel中的页眉页脚的设置方法:
LODOP.SET_SAVE_MODE("CENTERHEADER","中间的页眉");
LODOP.SET_SAVE_MODE("LEFTHEADER","左边的页眉");
LODOP.SET_SAVE_MODE("RIGHTHEADER","右边的页眉");
LODOP.SET_SAVE_MODE("CENTERFOOTER","中间的页脚");
LODOP.SET_SAVE_MODE("LEFTFOOTER","左边的页脚");
LODOP.SET_SAVE_MODE("RIGHTFOOTER","右边的页脚");

测试代码:

<script language="javascript" src="LodopFuncs.js"></script>
</head>
<body>
<div id="d1">
<table width="100%" border=1 style="border-collapse:collapse;">
<tr>
    <td id="td1">12</td>
    <td id="td2">12</td>
</tr>
<tr>
    <td id="td3">14</td>
    <td id="td4">32</td>
</tr>
<tr>
    <td id="s0">11</td>
    <td id="s1">23</td>
</tr>
</table>
</div>
<a href="javascript:OutToFileOneSheet()">导出带页眉页脚的表格</a><br>
<script language="javascript" type="text/javascript">   
        var LODOP; //声明为全局变量 
    function OutToFileOneSheet(){ 
        LODOP=getLodop();   
        LODOP.PRINT_INIT(""); 
        LODOP.ADD_PRINT_TABLE(100,20,500,60,document.getElementById("d1").innerHTML); 
        LODOP.SET_SAVE_MODE("CENTERHEADER","中间的页眉"); 
        LODOP.SET_SAVE_MODE("LEFTHEADER","左边的页眉"); 
        LODOP.SET_SAVE_MODE("RIGHTHEADER","右边的页眉"); 
        LODOP.SET_SAVE_MODE("CENTERFOOTER","中间的页脚"); 
        LODOP.SET_SAVE_MODE("LEFTFOOTER","左边的页脚"); 
        LODOP.SET_SAVE_MODE("RIGHTFOOTER","右边的页脚"); 
        LODOP.SAVE_TO_FILE("lodop导出带页眉页脚.xlsx"); 
        };
</script> 
</body>

图示:

posted @ 2020-01-07 14:05  花谢悦神  阅读(431)  评论(0编辑  收藏  举报