使用Office.Interop.Excel将文件另存为PDF/A [英] Save file as PDF/A using Office.Interop.Excel
问题描述
如何将 Excel 电子表格导出到PDF/ A (ISO 19005-1)?
How can I export an Excel spreadsheet to PDF/A (ISO 19005-1)?
我要的是PDF/A,不是纯旧的PDF 1.5,因为默认情况下它会导出.我甚至在原始问题中强调了 A .
I'm asking for PDF/A, and not plain old PDF 1.5 as it exports by default. I've even emphasized the A in my original question.
我已经可以使用 ExportAsFixedFormat()
函数将Word和PowerPoint文档导出到PDF/A,因为Word和PowerPoint函数都具有可选的 UseISO19005_1
参数,但是Excel版本却大不相同,并且缺少很多参数.
I can already export Word and PowerPoint documents to PDF/A, using the ExportAsFixedFormat()
function, since the Word and PowerPoint functions both have an optional UseISO19005_1
parameter, but the Excel version is very different, and is missing lots of parameters.
我似乎找不到使用COM Interop导出PDF/ A 的任何方法.
I can't seem to find any way to export a PDF/A using the COM Interop.
这是我用来从docx导出的代码:
Here's the code I use to export from a docx:
Dim ExportFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF
Dim OpenAfterExport As Boolean = False
Dim OptimizeFor As WdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint
Dim Range As WdExportRange = WdExportRange.wdExportAllDocument
Dim Item As WdExportItem = WdExportItem.wdExportDocumentWithMarkup
Dim IncludeDocProps As Boolean = True
Dim KeepIRM As Boolean = False
Dim CreateBookmarks As WdExportCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks
Dim DocStructureTags As Boolean = True
Dim BitmapMissingFonts As Boolean = True
Dim UseISO19005_1 As Boolean = False
If exportPDFA Then
UseISO19005_1 = True
Dim wordApp As New Word.Application()
Dim doc As Word.Document = wordApp.Documents.Open(FileName)
doc.ExportAsFixedFormat(pathToDestFile, ExportFormat, OpenAfterExport, OptimizeFor, Range, 0, 0, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1)
End If
但是对于xlsx, ExportAsFixedFormat()
函数接受非常不同的参数(此参数直接来自Microsoft.Office.Interop.Excel类):
But for xlsx, the ExportAsFixedFormat()
function accepts very different parameters (this was taken directly from the Microsoft.Office.Interop.Excel class):
Sub ExportAsFixedFormat(Type As XlFixedFormatType, Optional Filename As Object = Nothing, Optional Quality As Object = Nothing, Optional IncludeDocProperties As Object = Nothing, Optional IgnorePrintAreas As Object = Nothing, Optional From As Object = Nothing, Optional [To] As Object = Nothing, Optional OpenAfterPublish As Object = Nothing, Optional FixedFormatExtClassPtr As Object = Nothing)
推荐答案
Excel允许用户在保存对话框的选项中选择是否将文件另存为PDF/A.此设置在HKEY_CURRENT_USER \ Software \ Microsoft \ Office \ 12.0 \ Common \ FixedFormat下以LastISO19005-1(REG_DWORD)的形式存储在注册表中.(用正确的版本替换12.0.)ExportAsFixedFormat函数也遵循此设置.您可以在调用ExportAsFixedFormat之前使此值设置为1,以使Excel将文件导出为PDF/A.
Excel allows the user to choose whether or not to save the file as PDF/A in the options of the save dialog. This setting is stored in the Registry as LastISO19005-1 (REG_DWORD) under HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\FixedFormat. (Replace 12.0 with the right version.) The ExportAsFixedFormat function also respects this setting. You can set this value to 1 before calling ExportAsFixedFormat to get Excel to export the file as PDF/A.
我知道此解决方案并不理想,因为它使用全局状态来解决局部问题.完成后,请考虑恢复以前的值.
I know this solution is not pretty as it uses global state to address a local problem. Consider restoring the previous value when you're done.
这篇关于使用Office.Interop.Excel将文件另存为PDF/A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!