Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#(不是文件内容)以编程方式将整个文件插入MS word文档_C#_Asp.net_Ms Word - Fatal编程技术网

使用C#(不是文件内容)以编程方式将整个文件插入MS word文档

使用C#(不是文件内容)以编程方式将整个文件插入MS word文档,c#,asp.net,ms-word,C#,Asp.net,Ms Word,这是我的密码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Office.Interop.Word; names

这是我的密码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Word;
    namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                object missing = System.Reflection.Missing.Value;
                object fileName = @"C:\b.docx";
                Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
                Document adoc = WordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                Range rngPic = adoc.Tables[1].Cell(1, 2).Range;
                rngPic.InsertFile(@"C:\a.docx", ref missing, ref missing, ref missing, ref missing);
                WordApp.Visible = true;
            }
        }
    }
我的期望是
b.docx
应该包含文件
a.docx
,而
a.docx
的内容被添加到
b.docx

清楚地说,我需要以编程方式使用c#将a.docx插入b.docx,就像我们在word中插入对象一样

我需要将整个文件添加到word文档中。不是文件的内容帮我

最欢迎更正、建议和新代码。


请帮帮我。

我会使用OpenXMLSDK将您需要的
部分从a复制到b。搜索office open xml sdk部件。所有图像都是一部分,超链接是一部分,…@AlexanderDerck请提供一些教程视频和示例您是否尝试在插入文档作为对象时录制宏以获取基本语法?把VBA带到C#不是什么大问题,一旦你有了它。。。我希望它类似于Selection.InlineShapes.AddOLEObject,后面是参数,其中包含特定于要嵌入的文件类型的信息。如果您使用的是“Microsoft.Office.Interop.Word”,请查看以下答案: