打印时清空页眉页脚

<script language="JavaScript">
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="//Software//Microsoft//Internet Explorer//PageSetup//"
//设置网页打印的页眉页脚为空
function pagesetup_null()
{
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
}

</script>

<input type="button" value="清空页码" οnclick=pagesetup_null()>
<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="
http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"></object>
<script defer>
function window.onload() {
factory.printing.header = ""
factory.printing.footer = ""
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 1.5
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 1.5
}

</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spire中实现加载文档1,获取文档1的页眉页脚,加载文档2并清空文档2的页眉页脚,然后将页眉复制到目标文档的第三节以及后续节,并根据Word页面方向使页眉页脚自适应,可以使用以下代码: ```java import com.spire.doc.*; import com.spire.doc.documents.*; import com.spire.doc.fields.*; public class CopyHeaderFooter { public static void main(String[] args) { // 加载文档1 Document document1 = new Document(); document1.loadFromFile("document1.docx"); // 获取文档1的页眉页脚 HeaderFooter header1 = document1.getSections().get(0).getHeadersFooters().getHeader(); HeaderFooter footer1 = document1.getSections().get(0).getHeadersFooters().getFooter(); // 加载文档2 Document document2 = new Document(); document2.loadFromFile("document2.docx"); // 清空文档2的页眉页脚 document2.getSections().get(0).getHeadersFooters().clear(); // 创建目标文档 Document targetDocument = new Document(); // 复制文档2的内容到目标文档 Section section2 = document2.getSections().get(0); targetDocument.getSections().add(section2.deepClone()); // 获取文档2的页面方向 PageSetup pageSetup2 = section2.getPageSetup(); PageOrientation orientation2 = pageSetup2.getPageOrientation(); // 复制页眉到目标文档的第三节及后续节,并根据页面方向自适应 for (int i = 0; i < targetDocument.getSections().size(); i++) { Section section = targetDocument.getSections().get(i); // 获取当前节的页面方向 PageSetup pageSetup = section.getPageSetup(); PageOrientation orientation = pageSetup.getPageOrientation(); // 根据页面方向选择复制相应的页眉 if (orientation == PageOrientation.Portrait && orientation2 == PageOrientation.Portrait) { section.getHeadersFooters().setHeader(header1.deepClone()); } else if (orientation == PageOrientation.Landscape && orientation2 == PageOrientation.Landscape) { section.getHeadersFooters().setHeaderLandscape(header1.deepClone()); } } // 保存目标文档 targetDocument.saveToFile("output.docx", FileFormat.Docx); } } ``` 在这段代码中,我们首先加载文档1并获取其页眉页脚。然后,加载文档2并清空页眉页脚。接下来,我们创建目标文档,并将文档2的内容复制到目标文档中。然后,我们根据文档2的页面方向,在目标文档的第三节及后续节中复制相应的页眉。最后,将目标文档保存为"output.docx"文件。请确保将"document1.docx"和"document2.docx"替换为你实际的文件路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值