【问题标题】:Save PDF that is embedded in Excel as separate file将嵌入在 Excel 中的 PDF 保存为单独的文件
【发布时间】:2020-03-29 06:23:41
【问题描述】:

已更新 - 我正在使用 C# 从大量 Excel 工作簿中检索数据。工作簿中嵌入了一些重要的 pdf 文档。我需要将它们保存为单独的文档以供进一步处理。

我能够遍历所有工作表中的所有 oleObject 并找到所有 pdf。

我在 DocumentFormat.OpenXml.Spreadsheet 中使用 progID 来识别 pdf https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.oleobjects?view=openxml-2.8.1

  foreach(Worksheet ws in xlWb.Worksheets)
        {      
            foreach (OLEObject ole in ws.OLEObjects())
            {
                  //identify whether the oleObject is of AcroExch class type
                   if(ole.progID == "AcroExch.Document.DC")
                {
                   //2. Cast oleObject to AcroExch and save it as a pdf separately 
                }


            }
        }

根据我在网上收集的信息,使用 acrobat dc sdk 似乎是唯一的选择。 还有其他方法可以实现我想要的吗?

谢谢

【问题讨论】:

  • 我相信OLEObject.Creator属性可以用来表示Acrobat PDF文件。但是,我不知道 Acrobat 的 32 位值是多少。
  • stackoverflow.com/questions/52778729/… 这个线程中有一些代码,也许会有帮助
  • @Dai OLEObject.Creator 不起作用。我导入了 DocumentFormat.OpenXml.Spreadsheet 并使用 if(ole.progID == "AcroExch.Document.DC") 来识别 pdf
  • @AllenKing 谢谢。我最终使用了这个线程中的代码stackoverflow.com/questions/22358982/…

标签: c# excel comobject


【解决方案1】:

提取嵌入的pdf并保存为pdf,请参考GemBox开发团队提供的这个解决方案:
How to download embedded PDF files in an excel worksheet?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 2012-07-31
    相关资源
    最近更新 更多