以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- word在生成pdf前先删除页脚内容 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=139609) |
-- 作者:fntfgz -- 发布时间:2019/8/16 22:59:00 -- word在生成pdf前先删除页脚内容 word在生成pdf前先删除页脚内容,我分别找到了两段代码,但是删除页脚的是vba的,老师怎么把这两个融合到一起呢 Dim app As New MSWord.Application try Dim fileName = "D:\\pdfcs\\w.docx" app.Documents.Open(fileName) app.Documents(fileName).ExportAsFixedFormat("D:\\pdfcs\\w.pdf", MSWord.WdExportFormat.wdExportFormatPDF) catch ex As exception msgbox(ex.message) finally app.Quit End try 我也找到了删除页脚的vba代码 Sub 删除页脚内容() Dim j As Section Dim y As HeaderFooter For Each j In ActiveDocument.Sections For Each y In j.Footers y.Range.Delete Next Next End Sub |
-- 作者:有点蓝 -- 发布时间:2019/8/16 23:30:00 -- Dim app As New MSWord.Application try Dim fileName = "d:\\问题\\w.docx" Dim doc = app.Documents.Open(fileName) For Each oSec As object In doc.Sections Dim myRange = oSec.Footers(MSWord.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range myRange.Delete Next doc.saved = True doc.ExportAsFixedFormat("d:\\问题\\w.pdf", MSWord.WdExportFormat.wdExportFormatPDF) catch ex As exception msgbox(ex.message) finally app.Quit End try
|
-- 作者:fntfgz -- 发布时间:2019/8/17 10:07:00 -- 谢谢有点甜老师,这么晚还给回复问题,老师,在帮一下吧,我也想用excel实现相同的效果,先删除页脚然后在生成pdf, 本想有word的样子,自己先试试,但还是搞不定,下面是生成pdf 代码,请老师在费点时间,看看删除页脚在之前怎么实现,再次感谢 Dim App As New MSExcel.Application try Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("d:\\会议签到表.xls") \'创建Excel文件对应的PDF文件 wb.Saved = True wb.ExportAsFixedFormat(MSExcel.XlFixedFormatType.xlTypePDF, "d:\\会议签到表.pdf", MsExcel.XlFixedFormatQuality.xlQualityStandard, True, False, System.Reflection.Missing.Value, System.Reflection.Missing.Value, True, System.Reflection.Missing.Value) app.quit msgbox("OK") catch ex As exception msgbox(ex.message) app.quit End try
|
-- 作者:有点蓝 -- 发布时间:2019/8/17 11:03:00 -- 参考:http://www.foxtable.com/webhelp/topics/2121.htm Dim App As New MSExcel.Application try Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\\问题\\123.xls") Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) With Ws.PageSetup .LeftFooter = "" \'左页脚,&F表示文件名,&A表示工作表名 .CenterFooter = "" \'中页脚为空 .RightFooter = "" \'右页脚 End With \'创建Excel文件对应的PDF文件 wb.Saved = True wb.ExportAsFixedFormat(MSExcel.XlFixedFormatType.xlTypePDF, "D:\\问题\\123.pdf", MsExcel.XlFixedFormatQuality.xlQualityStandard, True, False, System.Reflection.Missing.Value, System.Reflection.Missing.Value, True, System.Reflection.Missing.Value) app.quit msgbox("OK") catch ex As exception msgbox(ex.message) app.quit End try |