在我们旧的基于MSWord-97的系统中,我们使用COM与.doc文件交互,并嵌入OLE对象,因此嵌入的文档在父级中可见(而不是图标).
我们用一个使用OpenXML SDK的系统取而代之,因为它需要在我们的服务器上安装Word,它会生成.docx文件.但是我们仍然需要将RTF文件的内容嵌入到生成的DOCX中...具体来说,我们用文件的内容替换书签.
我在网上找到了一些例子,但它们都有所不同.当我在Word中创建一个简单的示例并查看XML时,有很多东西可以定位/显示嵌入对象的可视化表示,而嵌入本身似乎并不太可怕.最简单的方法是什么?
我正在尝试这样做如何使用OpenXml 2.0将任何文件类型嵌入到Microsoft Word中
但只使用OpenXml SDK 2.5(没有互操作程序集)
我可以嵌入其他文字(或办公室)使用下面的代码示例从文件在这里
(我们需要参考的的NuGet和WindowsBase添加到DocumentFormat.OpenXml)
但我无法重构它以接受任何文件类型(pdf,mp3等)
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using v = DocumentFormat.OpenXml.Vml;
using ovml = DocumentFormat.OpenXml.Vml.Office;
using System.IO;
class Program
{
static void Main(string[] args)
{
//Just update the following 2 variables to point to existng files
string containingDocumentPath = @"C:\Temp\Word\ContainingDocument.docx";
string embeddedDocumentPath = @"C:\Temp\Word\EmbeddedDocument.docx";
CreatePackage(containingDocumentPath, embeddedDocumentPath);
}
private static void CreatePackage(string containingDocumentPath, string embeddedDocumentPath)
{
using (WordprocessingDocument package = WordprocessingDocument.Create(containingDocumentPath, WordprocessingDocumentType.Document))
{
AddParts(package, embeddedDocumentPath);
}
}
private static void AddParts(WordprocessingDocument …Run Code Online (Sandbox Code Playgroud) 我需要将 Excel 文档嵌入到 Word 文档中。我使用了这个问题的答案 -> How can I embed any file type into Microsoft Word using OpenXml 2.0;
一切正常,除了:
DrawAspect = OVML.OleDrawAspectValues.Icon允许您通过打开新的 Excel 实例来编辑 Excel 对象。但是,当我编辑数据时,它不会在Word文档中更新。
DrawAspect = OVML.OleDrawAspectValues.Content允许您直接在 Word 文档中编辑 Excel 对象。
我的问题是,我必须在代码中更改哪些内容,以便我可以在新实例中编辑 Excel 对象并将其正确反映在 Word 文档中?我尝试了一切都无济于事。
有件事告诉我,DrawAspect = OVML.OleDrawAspectValues.Icon该对象充当图标,并且更改无法正确反映在该图标中。