VSTO + Open XML Add-in

I would like to develop an add-on. This add-in should use open xml (not everything can be done with VSTO + Open XML much faster), BUT is there any way to edit an open document? For example, I opened a PowerPoint presentation (or Word / Excel docs spreadsheet) and I would like to replace some text with Open XML, can I read it (from what I read, reading is possible) and update without closing that file using Open XML of course? If so, how to do it?

There is some feeddata () method, memory streams, but I don't know how to use it. Can anyone provide an example?

+3


source to share


3 answers


Below code works for me:



Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;

string XML = doc.Content.WordOpenXML;

// XML Changes

doc.Content.InsertXML(XML);

      

+2


source


        var fileFullName = Globals.ThisAddIn.Application.ActiveDocument.FullName;

        Globals.ThisAddIn.Application.ActiveDocument.Close(WdSaveOptions.wdSaveChanges, WdOriginalFormat.wdOriginalDocumentFormat, true);

        //edit document using OpenXml here

        Globals.ThisAddIn.Application.Documents.Open(fileFullName);

      



This works for Word documents.

+1


source


The purpose of VSTO and Open XML is different.

VSTO basically expands office to your target when you run the addin in the context of an Office application. And you can use Com interceptors as they are already available.

Open XML is used for automation, for example, to create or edit documents, books in which you do not have an office application. for example, on Asp.net server, you don't need to install Office, but use Open XML to create, edit documents, spreadsheets or ppt.

In your case, if you are going to use the VSTO approach, you do not need to use the Open XML sdk. Use the available find and replace functions in the appropriate interpolators. Don't forget to save the document, xls or ppt after replacement

Word

Excel

Powerpoint

0


source







All Articles