【问题标题】:SharePoint and Office Open XML interaction questionSharePoint 和 Office Open XML 交互问题
【发布时间】:2008-11-23 22:35:08
【问题描述】:

整个周末,再加上一两天,我都为此感到沮丧,所以任何帮助都将不胜感激。

我正在尝试编写一个程序,该程序可以以编程方式进入 SharePoint 2007 文档库、打开文件、更改文件内容,然后将文件放回原处。除了最后一部分之外,我已经完成了所有工作。涉及 Office Open XML 的原因是我通过 Office Open XML SDK 打开和修改文档的方式。我的问题是:如何将它从文档中取回图书馆?

我看到的问题是 WordprocessingDocument 对象本身没有保存功能。这使我无法将其保存到 SPFile 的 SaveBinary 函数中。

【问题讨论】:

    标签: sharepoint ms-word openxml


    【解决方案1】:

    您应该使用流将更改的 OOXML 写回 SPFile。 我希望这个例子有帮助!

    Stream fs = mySPFile.OpenBinaryStream();
    
    using (WordprocessingDocument ooxmlDoc = WordprocessingDocument.Open(fs, true))
    {
    
        MainDocumentPart mainPart = wordDoc.MainDocumentPart;
        XmlDocument xmlMainDocument = new XmlDocument();
        xmlMainDocument.Load(mainPart.GetStream());
    
       // change the contents of the ooxmlDoc / xmlMainDocument
    
       Stream stream = mainPart.GetStream(FileMode.Open, FileAccess.ReadWrite);
       xmlMainDocument.Save(stream);
       // the stream should not be longer than the DocumentPart
       stream.SetLength(stream.Position); 
    }
    mySPFile.SaveBinary(fs);
    fs.Dispose();
    

    【讨论】:

      【解决方案2】:

      昨天我看到了 Andrew Connell 的网络广播,他从文档库中打开了一个文档,添加了水印并再次保存了文件。听起来您确实应该看一下该网络广播: https://msevents.microsoft.com/CUI/WebCastRegistrationConfirmation.aspx?culture=en-US&RegistrationID=1299758384&Validate=false

      顺便说一句,我发现该系列中的所有 10 个网络广播都非常好。

      【讨论】:

      • 我尽可能地尝试做他所做的事情。但是,他没有显示将项目放回 SharePoint 的代码!真的很烦人(不是我在责怪你。他很烦人)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多