在此上下文中不存在名称 SpaceProcessingModeValues

本文关键字:SpaceProcessingModeValues 不存在 上下文 | 更新日期: 2023-09-27 18:36:06

在我的 ASP.net 程序中,我有一个类来打开一个word文档,找到一个布尔标记并插入给定的文本

我得到的错误是:名称SpaceProcessingModeValues在当前上下文中不存在。

using (WordprocessingDocument document = WordprocessingDocument.Open(strFileName, true))
    {
        MainDocumentPart mainPart = document.MainDocumentPart;
        IEnumerable<BookmarkStart> res = from bm in      mainPart.Document.Body.Descendants<BookmarkStart>()
            where bm.Name == "strField"
            select bm;
        int x = 0;
        BookmarkStart bookmark = res.SingleOrDefault();
        if (bookmark != null)
        {
            OpenXmlElement parent = bookmark.Parent; // bookmark's parent element
            var paragraph1 = new Paragraph {RsidParagraphAddition = "00023529", RsidRunAdditionDefault = "003E1BA6"};
            var run1 = new Run();
            var text1 = new Text("Text : "){ Space = SpaceProcessingModeValues.Preserve };
            run1.Append(text1);
            var bookmarkStart1 = new BookmarkStart {Name = "_GoBack", Id = 0};
            var bookmarkEnd1 = new BookmarkEnd {Id = 0};
            var run2 = new Run();
            var text2 = new Text();
            text2.Text = strGivenText;
            run2.Append(text2);
            paragraph1.Append(run1);
            paragraph1.Append(bookmarkStart1);
            paragraph1.Append(bookmarkEnd1);
            paragraph1.Append(run2);
            parent.InsertBeforeSelf(paragraph1);
        }
        // close saves all parts and closes the document
        mainPart.Document.Save();
        document.Close();
    }

在此上下文中不存在名称 SpaceProcessingModeValues

您需要添加引用 DocumentFormat.OpenXml 命名空间

相关文章:
  • 没有找到相关文章