明明已经添加引用,为何报错没有添加引用。

解决方案 »

  1.   

    [code=csharp]using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Presentation;
    using DocumentFormat .OpenXml.Packaging;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
          
            //how to create a package
            public static void CreateNewWord(string document)
            {
                using(WordprocessingDocument worddoc=WordprocessingDocument.Create(document ,WordprocessingDocumentType.Document ))
                {
                    MainDocumentPart mainpart = worddoc.AddMainDocumentPart();
                    SetMainDocumentContent(mainpart );            }
            }
            public static void SetMainDocumentContent(MainDocumentPart part)
            {
                const string docXml =
     @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?> 
    <w:document xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"">
        <w:body><w:p><w:r><w:t>Hello world!</w:t></w:r></w:p></w:body>
    </w:document>";                    using (Stream stream=part.GetStream())
                        {
                            byte[] buf = (new UTF8Encoding()).GetBytes(docXml);
                            stream.Write(buf, 0, buf.Length);
                        }
            }
        }
    }
    code]