Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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# 无法使用打开的XML SDK创建文档_C#_.net_Visual Studio_Openxml_Openxml Sdk - Fatal编程技术网

C# 无法使用打开的XML SDK创建文档

C# 无法使用打开的XML SDK创建文档,c#,.net,visual-studio,openxml,openxml-sdk,C#,.net,Visual Studio,Openxml,Openxml Sdk,我正在学习在Visual Studio Community 2015中使用开放式XML SDK。我尝试通过以下示例创建文档: 我的代码: using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; namespace ConsoleApplication1 { class Program { s

我正在学习在Visual Studio Community 2015中使用开放式XML SDK。我尝试通过以下示例创建文档:

我的代码:

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          Program p = new Program();
          p.HelloWorld("abc.docx");
        }

        public void HelloWorld(string docName)
        {
            // Create a Wordprocessing document. 
            using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
            {
                // Add a new main document part. 
                package.AddMainDocumentPart();

                // Create the Document DOM. 
                package.MainDocumentPart.Document =
                  new Document(
                    new Body(
                      new Paragraph(
                        new Run(
                          new Text("Hello World!")))));

                // Save changes to the main document part. 
                package.MainDocumentPart.Document.Save();
            }
        }

    }
}
我在
字处理文档上出错。创建

Error   CS0012  The type 'Package' is defined in an assembly that is not referenced. 
You must add a reference to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=1234'.  
ConsoleApplication1 c:\users\john\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
我已经用nuget安装了
DocumentFormat.OpenXml


代码有什么问题?

错误消息已经告诉您如何解决问题:

必须添加对程序集“WindowsBase,版本=4.0.0.0,区域性=中性,PublicKeyToken=1234”的引用


在Visual Studio的解决方案资源管理器中右键单击项目的“引用”节点,然后选择“添加引用”。然后,在Assemblies->Framework下,您必须选择WindowsBase并将其作为参考。然后重新编译您的项目(请注意,这要求您使用的是.NET Framework 3.5或任何更高版本)。

感谢您以清晰的步骤为我指明了正确的方向。我不知道这个错误消息是什么意思。