简体   繁体   English

使用openxml和C#将Excel嵌入Powerpoint 2007

[英]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. 我正在尝试使用openxml将与图表相关的Excel 2007文件嵌入到pptx 2007中。 I manually created a empty PPTx contains one slide then i did: 我手动创建了一个包含一张幻灯片的空PPTx,然后执行了以下操作:

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). 从本质上讲,这是SDK代码反射器的编写方式,除了二进制数据位于字符串中(我正在打开文件)之外,保存。 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. 但是,这段代码将“ package.bin”文件放在xl \\ drawings \\ charts \\ embeddings \\中,而我的手动嵌入将文件放入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? 有没有人遇到此问题,并找到一种方法来克服文件以及“ .bin”扩展名的不正确放置?

Thanks in advance! 提前致谢!

Just solved the problem by adding 2 lines :) 刚刚通过添加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_FILE\data.xlsx", FileMode.Open, FileAccess.ReadWrite));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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