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 xldrawingschartsembeddings whereas my manual embedding puts the file into pptembeddings. 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!


刚刚通过添加2行解决了这个问题:)

// 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_FILEdata.xlsx", FileMode.Open, FileAccess.ReadWrite));
链接地址: http://www.djcxy.com/p/52342.html

上一篇: openxml 2.5,如何将字符串插入单元格?

下一篇: 使用openxml和C#将Excel嵌入到Powerpoint 2007中