gpt4 book ai didi

excel - 使用VS2008和Office2007将Excel转换为PDF

转载 作者:行者123 更新时间:2023-12-01 22:35:04 25 4
gpt4 key购买 nike

我正在尝试使用 Interop.Excell 将 Excel 工作簿另存为 PDF 文件。我使用的是VS2008和Office2007,并从Microsoft下载并安装了SaveAsPDFandXPS.exe。这使我能够使用以下代码将 Word 文档另存为 pdf: 对象 frmt = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; wrd.ActiveDocument.SaveAs(引用目标,引用 frmt,引用未知,引用未知,...除了整个互操作性之外,非常酷。

无论如何,我未能在 Interop.Excell 中找到 Word.WdSaveFormat.wdFormatPDF 的相似之处。 Workbook.SaveAs 采用 Interop.Excel.XlFileFormat,但没有 pdf 格式的选项。有人做过这件事或者有这方面的经验吗?

最佳答案

这个问题已在这里得到解答:

What is the FileType number for PDF in Excel 2007 that is needed to save a file as PDF through the API?

您需要调用Workbook.ExportAsFixedFormat方法:

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF 
FileName:=“sales.pdf”
Quality:=xlQualityStandard
DisplayFileAfterPublish:=True

此方法应该优于使用 SaveAs,因为它还允许指定所有 PDF/XPS 选项。

注意:此方法已添加到 Excel 2007 的 Excel 对象模型中,并且需要 Save as PDF or XPS Add-in安装 2007 Microsoft Office 程序(或 SP2)。

关于excel - 使用VS2008和Office2007将Excel转换为PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/634990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com