打开XML SDK来编辑Active文档
是否可以使用 Open XML sdk 来操作当前在 Office 应用程序中打开的文档部分(word/ppt)。我知道最简单的方法是使用 VSTO,但它很慢并且需要使用剪贴板来插入元素,OXML sdk 更直接、更简单。
如果有人可以发布一些代码示例,那就太好了。
提前致谢
拉凯什
Is it possible to use the Open XML sdk to manipulate parts of document which is currently open in the Office app (word/ppt). I know the easiest thing is to use VSTO, but its slow and would involve clipboard use to insert elements, the OXML sdk is direct and simpler.
If somebody could post some code sample that would be great.
Thanks in advance
Rakesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,可以使用 OpenXML sdk 2 修改打开的 VSTO 文档,然后使用更改后的 xml 更新打开的文档。
http://msdn.microsoft.com/en-us/library/ff191178.aspx
http://code.msdn.microsoft.com/Improve-Automation-415bff13基本上
,您从一个范围中获取 xml,将其视为流,将其打包,使用包上的 sdk,然后通过相反的过程将修改后的 xml 插入回来。
众所周知,这种 sdk 的常识用法是不可能的。然而,这是错误的。
Yes it is possible to modify an open VSTO document, using the OpenXML sdk 2, then update your open document using the changed xml.
http://msdn.microsoft.com/en-us/library/ff191178.aspx
http://code.msdn.microsoft.com/Improve-Automation-415bff13
Basically you get the xml from a range, treat it as a stream, package it up, use the sdk on the package, then insert the modified xml back by reversing the process.
The wisdom out there is that this common sense usage of the sdk is not possible. However, this is just wrong.
如下所示:-
另外,您可以使用 LINQ 来避免 foreach 循环。
Something like below:-
Also, you could use LINQ to avoid foreach loops.
我能够使用 ClosedXML 使用 Excel 文档来执行此操作(将文件作为路径 excelFileName 保存到磁盘后):
在我的情况下,我只读取文档,不会保存它,但您可以写入修改后的流如有必要,到另一个文件。
I was able to do this using an Excel Document using ClosedXML as such (after saving the file to disk as the path excelFileName):
In my case I am only reading the document and will not be saving it, but you could write the modified stream to another file if necessary.
显然,如果没有 Sharepoint,你就无法做到这一点。
根据 Zeyad Jarabi/..
Apparently you cannot do this without Sharepoint.
As per Zeyad Jarabi/..