简体   繁体   中英

How to edit ms word document that is open live in add-in?

I am a beginner in C# and VSTO trying to make an ms word add-in that edits/modifies a live word document that is already open.

I've looked into many of APIs, such as OpenXml, Spire, etc.

But, most of them seem to be used against a word file that is not open

due to the file lock when it is open.

It looks like you can edit an opened document to a degree with InterOp or OpenXML by creating a document in memory. I've tried to understand how the latter works, but I have not been able to do so.

Am I missing out on something here?

Could anyone help me by giving pointers as to how to approach this problem or where to look for resources?

What do you suggest that I should try as my best shot for this problem?

I'd very much appreciate to get some advice from any skilled VSTO developers as a noob.

Thank you in advance for your help,

frogy

There are several options to editing the Word document while you are -in- the document. First you have to decide on the technology used. In general there are four recommended technologies (there are more, but these four give you the option to work from an active document open in Word.

  • VBA, the Visual Basic
  • COM, just using the Office COM Object Model
  • VSTO, like COM but extended with added tooling on top to make life easier
  • OfficeJS, the new Office API Add-in Model

At this time it is recommended to start with the last option as it it 'prepared for the future', cross platform etc. see https://dev.office.com/getting-started/addins to explore how to start with this.

Your question however is specific to C# and VSTO, the third option, here is a starter to get you going:

https://msdn.microsoft.com/en-us/library/cc442946.aspx

There is a lot more where that came from, but first try some things and come back if you hit specific issues you want to ask about.

Make sure your questions are small and limited to the issue you run into, added with examples what you tried and what the expected output is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM