简体   繁体   中英

Embed Excel into Powerpoint 2007 using openxml and C#

Running into two problems that I'm hoping someone can assist.

I am trying to embed a excel 2007 file in relationship with a chart into pptx 2007 programmatically using openxml. I manually created a empty PPTx contains one slide then i did:

EmbeddedPackagePart newEmbeddedPackagePart = slidePart.AddNewPart<EmbeddedPackagePart>("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","rId10");
newEmbeddedPackagePart.FeedData(File.Open(@"C:\Book1.xlsx", FileMode.Open));
Drawing.Charts.ExternalData newEmbeddedPackagePart = new DocumentFormat.OpenXml.Drawing.Charts.ExternalData();
newEmbeddedPackagePart.Id = "rId10";

Which is basically how the SDK code reflector wrote it, save except the binary data was in a string (where I am opening a file). However, this piece of code places a "package.bin" file in xl\\drawings\\charts\\embeddings\\ whereas my manual embedding puts the file into ppt\\embeddings. Has anyone experienced this problem, and found a way to overcome the incorrect placement of the file, as well as the ".bin" extension?

Thanks in advance!

Just solved the problem by adding 2 lines :)

// Create new Embedded Package Part    
EmbeddedPackagePart embPackage = myChartPart.AddNewPart<EmbeddedPackagePart>("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "rId1"); 
// Feed imported data from an excel file into the embedded package               
embPackage.FeedData(new FileStream(@"C:\PATH_TO_FILE\data.xlsx", FileMode.Open, FileAccess.ReadWrite));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM