Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a word file that should be embedded in excel file. I can put a word file, but it only shows as .bin file inside excel zipped file. How can I make it visible inside excel (let's say at position cell C3)? I also need to edit that embeded word file later. Interop is not an answer, because this project should work on a server machine. Thank you. So far i tried something like this.

public static void addWordFile(string fileName, string tableDoc)
{
    using (SpreadsheetDocument  document = SpreadsheetDocument.Open(fileName, true))
    {

        WorkbookPart wbPart = document.WorkbookPart;


        // Find the sheet with the supplied name, and then use that 
        // Sheet object to retrieve a reference to the first worksheet.
        Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
          Where(s => s.Name == "Test4").FirstOrDefault();

        // Throw an exception if there is no sheet.
        if (theSheet == null)
        {
            throw new ArgumentException("sheetName");
        }

        // Retrieve a reference to the worksheet part.
        WorksheetPart wsPart =
            (WorksheetPart)(wbPart.GetPartById(theSheet.Id));



        EmbeddedPackagePart newEmbeddedPackagePart = wsPart.AddNewPart<EmbeddedPackagePart>(@"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "rId100");
        newEmbeddedPackagePart.FeedData(File.Open(@tableDoc, FileMode.Open));
      

    }
}
Posted
Comments
NightWizzard 2-Feb-16 2:10am    
You can use the macro recorder while doing it manually to see, how Microsoft would nsolve the problem :-)
Lenin Mathi 31-Aug-20 4:08am    
Ivica Vesic - Pidzi - is it possible to do the same using closedXML? because i have implemented data population in excel macro.

If incase if i use the above solution, where do i get the file types for pdf, tif etc
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"

1 solution

Nevermind, I stoped searching for this, even if I foind out how, I have to generate screenshot for a file everytime embeded file get updated because the view of the file is actually just an image. Thank you anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900