Editing Word for Office Web Applications

The idea is to create a proprietary, basic Java document system using Office Web Apps.

We have created a WOPI client that allows us to view / edit PowerPoint and Excel documents, but we can view Word documents.

To edit Word Web App documents, you need to implement MS-FSSHTTP.

There seems to be no information on how to do this in code. Did anyone do this or would know how?

+4
source share
2 answers

Recently, my team and I introduced WOPI-Host, which supports viewing and editing Word, PPT and Excel documents. You can look at https://github.com/marx-yu/WopiHost , which is a command line project that listens on port 8080 and allows you to edit and view text documents even though Microsoft Office Web Apps.

We implemented this solution in webApi and it works great. Hope this sample project helps you.

After the request, I will try to add some code examples to clarify the way to implement it based on my webApi implementation, but there are a lot of code to implement to make it work correctly.

First of all, to enable editing, you will need to capture the HTTP messages in the FileController. Each post related to actual editing will have an X-WOPI-Override header equal to COBALT . In this post you will learn that InputStream is of type Atom. Based on the MS-WOPI documentation, in your answer you will need to include the following X-WOPI-CorrelationID and request-id headers.

Here is the code for my webApi publishing method (it is not complete since I am still implementing this WOPI protocol).

 string wopiOverride = Request.Headers.GetValues("X-WOPI-Override").First(); if (wopiOverride.Equals("COBALT")) { string filename = name; EditSession editSession = CobaltSessionManager.Instance.GetSession(filename); var filePath = HostingEnvironment.MapPath("~/App_Data/"); if (editSession == null){ var fileExt = filename.Substring(filename.LastIndexOf('.') + 1); if (fileExt.ToLower().Equals(@"xlsx")) editSession = new FileSession(filename, filePath + "/" + filename, @"yonggui.yu", @"yuyg", @" yonggui.yu@emacle.com ", false); else editSession = new CobaltSession(filename, filePath + "/" + filename, @"patrick.racicot", @"Patrick Racicot", @" patrick.racicot@hospitalis.com ", false); CobaltSessionManager.Instance.AddSession(editSession); } //cobalt, for docx and pptx var ms = new MemoryStream(); HttpContext.Current.Request.InputStream.CopyTo(ms); AtomFromByteArray atomRequest = new AtomFromByteArray(ms.ToArray()); RequestBatch requestBatch = new RequestBatch(); Object ctx; ProtocolVersion protocolVersion; requestBatch.DeserializeInputFromProtocol(atomRequest, out ctx, out protocolVersion); editSession.ExecuteRequestBatch(requestBatch); foreach (Request request in requestBatch.Requests) { if (request.GetType() == typeof(PutChangesRequest) && request.PartitionId == FilePartitionId.Content) { //upload file to hdfs editSession.Save(); } } var responseContent = requestBatch.SerializeOutputToProtocol(protocolVersion); var host = Request.Headers.GetValues("Host"); var correlationID = Request.Headers.GetValues("X-WOPI-CorrelationID").First(); response.Headers.Add("X-WOPI-CorrelationID", correlationID); response.Headers.Add("request-id", correlationID); MemoryStream memoryStream = new MemoryStream(); var streamContent = new PushStreamContent((outputStream, httpContext, transportContent) => { responseContent.CopyTo(outputStream); outputStream.Close(); }); response.Content = streamContent; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentLength = responseContent.Length; } 

As you can see in this method, I use CobaltSessionManager and CobaltSession , which are used to create and manage editing sessions in the Cobalt protocol. You will also need what I call CobaltHostLockingStore, which is used to handle various requests when communicating with the Office Web App server in the initialization of the publication.

I will not post code for these 3 classes, as they are already encoded in the github project of the sample that I posted, and that they are quite simple to understand, although they are large.

If you have more questions or if it is not clear enough, feel free to comment, and I will update my message accordingly.

+4
source

Patrick Rasicot gave a great answer. But I had a problem saving docx (exception in CobaltCore.dll), and I even started using the dotPeak reflector, trying to figure it out.

But after I locked the editSession variable in my WebApi method, everything began to work like magic. It seems that OWA sends requests that should be handled as a chain, rather than in parallel, as the controller method normally does.

0
source

Source: https://habr.com/ru/post/1487921/


All Articles