dotnet / Open-XML-SDK

Open XML SDK by Microsoft
https://www.nuget.org/packages/DocumentFormat.OpenXml/
MIT License
4.03k stars 547 forks source link

Add Objects (PDFs, Excel, Image, Word etc) and update the icon image and captions programmatically using OpenXML #1803

Open AlgorithmicThoughts opened 4 weeks ago

AlgorithmicThoughts commented 4 weeks ago

I'm working on an ASP.NET project where I am developing an endpoint that uses OpenXML to generate an Excel file. Additionally, I create a PDF document using a third-party tool. I need to insert the PDF stream into an Excel sheet (similar to insert object option of the excel). I discovered via a StackOverflow post that this can be done using COM Interop which I want to avoid as this would mean storing the Excel DLLS on the server and starting a new instance of excel whenever I want to add the PDFs into the excel (please correct if my understanding is incorrect).

I would also like to update the icon and the caption of the attached PDF object (this is also a requirement I am currently looking into but was not able to get an answer to)

image

Is there a way to insert the PDF stream directly into the Excel sheet and update it's icon and caption without relying on COM? Are there existing options to achieve this?

Describe the solution you'd like

A method to embed PDF streams and update its icon image and captions into Excel sheets directly using OpenXML, eliminating the need for COM Interop or any third party.

Here's what I know so far but it does not work in my case

  1. Using COM Interop to embed the PDF, which isn't feasible in my case.
  2. Converting the PDF to an image and embedding it, which isn't ideal for maintaining document integrity.
  3. Including a hyperlink to the PDF location, which doesn't truly embed the document in the Excel file.

This feature would greatly enhance the flexibility and functionality of OpenXML, providing a more seamless experience for developers needing to embed various objects in Office documents.

ThomasBarnekow commented 2 days ago

@AlgorithmicThoughts, do you know exactly what Open XML markup you'll have to generate for that purpose and what other binary parts, if any, will have to be changed to create the desired effect? If you knew what the result should look like, you could build that using the Open XML SDK.