SharePoint 和 Office Open XML 交互问题

发布于 2024-07-09 00:36:33 字数 326 浏览 7 评论 0原文

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

我正在尝试编写一个程序,该程序可以以编程方式进入 SharePoint 2007 文档库,打开文件,更改文件的内容,然后将文件放回去。 我已经把除了最后一部分以外的所有内容都记下来了。 涉及 Office Open XML 的原因是,这就是我打开文档并修改它的方式 - 通过 Office Open XML SDK。 我的问题是:如何将其从文档中取回到库中?

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

I've been frustrated by this for the entire weekend, plus a day or two, so any help would be significantly appreciated.

I'm trying to write a program that can programmatically go into a SharePoint 2007 doc library, open a file, change the contents of the file, then put the file back. I've gotten all but the last part of this down. The reason Office Open XML is involved is that that's how I'm opening the document and modifying it - through the Office Open XML SDK. My question is: How do I get it from the document back into the library?

The problem as I see it is that there's no save function on the WordprocessingDocument object itself. This prevents me from saving it into the SPFile's SaveBinary function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-07-16 00:36:33

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

Stream fs = mySPFile.OpenBinaryStream(); 

  使用 (WordprocessingDocument ooxmlDoc = WordprocessingDocument.Open(fs, true)) 
  { 

      MainDocumentPart mainPart = wordDoc.MainDocumentPart; 
      XmlDocument xmlMainDocument = new XmlDocument(); 
      xmlMainDocument.Load(mainPart.GetStream()); 

     // 更改 ooxmlDoc / xmlMainDocument 的内容 

     Stream 流 = mainPart.GetStream(FileMode.Open, FileAccess.ReadWrite); 
     xmlMainDocument.Save(流); 
     // 流不应比 DocumentPart 长 
     流.SetLength(流.位置);  
  } 
  mySPFile.SaveBinary(fs); 
  fs.Dispose(); 
  

You should use stream's to write back the changed OOXML into the SPFile.
I hope this example helps!

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();
撩动你心 2024-07-16 00:36:33

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

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

Yesterday I saw a webcast with Andrew Connell where he opened a doc from a doc library, added a watermark and saved the file again. It sure sounds like you should have a look at that webcast:
https://msevents.microsoft.com/CUI/WebCastRegistrationConfirmation.aspx?culture=en-US&RegistrationID=1299758384&Validate=false

btw I found that all 10 of the web casts in that serie were very good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文