Open a docx file using the ms-word protocol - ms-word

My goal is to use a deep link to open a Word document with the Word desktop app on the client's machine.
"ms-word:ofv|u|file:///C:Users/John/Documents/example.docx"
Chrome recognizes this protocol and wants to open Word, but upon opening it I get an error saying the command is not recognized.
There is a doc for it, but it's not complete at all, typical of MSDN docs...
https://learn.microsoft.com/en-us/office/client-developer/office-uri-schemes
I tried different variantions, like:
file://\C:Users\John\Documents\example.docx
file:\\\C:Users\John\Documents\example.docx
C:Users/John/Documents/example.docx
...
I then stumbled upon this question: Details of Microsoft Office Url protocol?
So through this process, the executable used is protocolhandler.exe in the Office16 directory.
Next, I tried opening a docx file using the Word executable WINWORD.EXE, and although it opens word, it doesn't find the specified file.
"C:\Program Files\Microsoft Office\Office16\WINWORD.EXE" "C:/Users/John/Documents/example.docx"
I also tried with the protocol just in case, and other variants but to no avail.
Edit:
Using "C:\Users\John\Documents\example.docx" (anti slash), I was able to open my docx file using the WINWORD.EXE.
So it really only is a syntax problem with the ms-word protocol

Related

WOPI corrupting files on edit

I have a WOPI host running in a Blazor server application with all of the .wopitest tests passing for the desired functionality (others skipped).
When I upload a word document, I am able to view the document with no issues. I am also able to edit the document, however when I try and edit the document a second time, I get an error.
The error doesn't appear to be handled and seems to originate in the Office online javascript file.
Error on attempting second edit
Following the error, I am still able to open the document for viewing. It is the same behaviour if I use the 'Editing' button in the Office Online page or directly navigate to the editing page using an edit action url.
Supplementary information:
Using ngrok to debug locally
.NET 6
Using SQLite database for holding file information (including path to file)
Using local folders for storing file contents (e.g. 'data' folder containing all files)
Similar issues with .xslx files beign corrupted upon editing and requiring a 'repair' when opened with Excel. This repair removes cells containing text and indicates that it removes the theme.
Viewing a word document gives the following console errors View document error
The first editing of a word document gives the following console errors Edit document error
I was expecting to be able to repeatedly edit the document.
I tried opening the file in the Desktop version of Word and got the following error Desktop Word recover
Following a recover, the document appears to work as expected in Word (desktop) but still won't open for editing through WOPI.
Turns out it was the way the POST http request body was being saved.
Still not certain what was going wrong but somewhere along the way of writing the stream into a buffer and then saving that to a file corrupted the file.
I suspect the file stream was either truncating or adding a few bytes.
The interesting part being that Office Online was still able to view the file.
This indicates there is some tolerance for malformed files still being served.

Convert HTML to a Word-document which can be edited in Word Online

Our users write in a rich-text field, pretty much like this one, and we would like for them to be able to export this as a Word Document in their OneDrive, preserving the formatting, and being able to open the file in Word Online.
I have no trouble creating new files using the https://graph.microsoft.com/v1.0/ api. The problem is the conversion to docx. The google api provides this conversion automatically, but I did not find that for Microsoft. I tried using html-docx-js and it almost works perfectly.
The file is created:
However when opening the file the following dialog pops up:
Opening in read-only mode works, the file shows with the correct formatting.
Downloading the file and opening in desktop word works perfectly (i.e. editing as well).
The HTML-content i use is a simple div with a few p-tags, so the "Objects that Word Online doesn't support" probably comes from html-docx-js.
Here's an example word-file that is created. This file can be opened as normal in desktop Word but only opened in read-only in Word Online
https://1drv.ms/w/s!AqpUGtnMiyurgwE543OscH7PdLnY
Any ideas?

Opening OneDrive file in desktop Word

I'm trying to open a file for edit from Office365's OneDrive in desktop version of Word(I'm logged in with my Office 365 account) using ms-word protocol and I have noticed that there are several possibilities:
Sometimes file opens in edit mode, I can edit file and by pressing Ctrl + S save it directly to OneDrive without being prompted for any additional actions.
Sometimes file opens in Read Only mode, I can switch to Editor mode, but then when I try to save file I'm prompted to specify save location(default location is my OneDrive directory with this file).
Sometimes Word asks me to login to my Office365 account(even though I'm logged in with this account in Word), then opens file in Read Only mode and after it looks like 2nd case.
I would like to open it as described in 1st case so user doesn't have to make any additional actions.
My current scenario is:
User calls an API to create file.
API creates file in user's OneDrive using Microsoft Graph.
API returns direct URL to file and I open this file in Word using ms-word protocol.
By direct URL to file I mean: https://domain-my.sharepoint.com/personal/account/Documents/Apps/Microsoft Graph/appname/directoryname/filename.docx
URL to open file looks like:
ms-word:ofe|u|<file path specified above>
And as I described at the beginning there are 3 cases how file is opened and it looks randomly for me.
I have also noticed that when I open my file in Word Online(using web url to file) and then I press Edit in Word it uses exactly the same file URL I have created and returned to user but from here the file always open with 1st scenario.
Do you have any ideas why this behaves differently when I manually open file using ms-word protocol compared to Word Online using ms-word protocol with exactly the same url?
I would like to always open file from user's OneDrive in desktop Word in scenario when user doesn't have to make any additional steps to edit and save file back to OneDrive.
(I don't have reputation so I can't comment. I will try again with a partial answer.)
There is always a chance that the credentials will have to be refreshed, so there is no way to completely prevent Office apps from prompting for credentials but it should be relatively uncommon.
As to the issue of opening in edit mode vs protected mode: There are a variety of reasons why some files will open into protected view: https://support.office.com/en-us/article/What-is-Protected-View-d6f09ac7-e6b9-4495-8e43-2bbcdbcb6653
If you have a file that seemingly opens in edit mode vs some version of readonly or protected view, please use answers.microsoft.com where the conversation doesn't have to fit into the stackoverflow model.
when I open my file in Word Online(using web url to file) and then I press Edit in Word it uses exactly the same file URL
You suggest that the URLs are identical, but my first thought was that the difference may have been that the Word Online link uses the driveItem's webDavUrl property rather than baseItem's webUrl
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem#json-representation

Programmatically convert Doc(x) files to PDF using Microsoft Word

We are developing a Java application that needs to programmatically convert .rtf, .doc and .docx files to PDF files.
Formatting is important to us, so we need the page numbers to be the same between a source file and a target PDF file, and the contents of each page being the same as the original file.
We have tried out open source solutions, such as JODConverter to invoke a LibreOffice of OpenOffice installation, Docx4j and XDocReport. The best formatting was achieved with LibreOffice. However, even in that case, the pages were different (for example, a 87-page .rtf file results in an 80-page PDF file).
So, we think that the ideal way to make the conversion would be to somehow invoke Microsoft Word though our Java application, and make the conversion with it. That would produce PDF files that have the same formatting as the original files.
Is this possible in any of the following ways:
An API that is directly invokeable through Java?
An API that is invokeable through a .Net language and we would use that with something like JACOB?
A 3rd party library that uses a Microsoft Word installation under the hood (something like JODConverter for Word)?
A CLI interface supported by Word (relevant question)?
Something else?

Convert from Microsoft Word to Media Wiki Markup Style

How do I export a word document to media wiki markup style
I have been trying to do it by following the steps given in http://en.wikipedia.org/wiki/Help:WordToWiki
but all in vain, not getting it.
Any help please.
Best way is to use Open Office
Open the Word document in Open Office Writer.
Go to File / Export.
Under File format choose MediaWiki (.txt).
Click Save (or Export).
Open the new file in a text editor and copy the contents to the clipboard.
Paste the text to a Wikipedia article.
That is copy and pasted from the document you linked to.
For Open Office 4.15 you have to add the extension Sun Wiki Publisher 1.1 with the extension manager.
If you don't want to install OpenOffice, another option is the Word2MediaWikiPlus extension.
In Microsoft Word 2016 I use the plugin "Microsoft Office Word Add-in For MediaWiki" (already suggested by Jake). https://www.microsoft.com/en-us/download/details.aspx?id=12298
To make it work in Microsoft Word 2016 (version 16.0). I followed these instructions but replaced "15.0" in the instruction to "16.0",
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_other/using-microsoft-office-word-add-in-for-mediawiki/449726c2-6d08-45e1-919a-4b5082ab4b5b
Microsoft has released an add-in for Microsoft Word that lets you export a doc file to MediaWiki formatting (as a .txt file). It's fairly decent.
http://www.microsoft.com/en-us/download/details.aspx?id=12298
If you're going to be doing this a lot, consider installing the FCK Editor. This has a Paste From Word button.
The easiest way may be to install LibreOffice (http://libreoffice.org) and open the Word document in its Writer application, then from there do Export and save to Media Wiki txt file. The Copy-paste that text into the Media Wiki at edit mode
but there was no way for adding images automatically that won't work for libreoffice or the word plugin.
If you have only a few docs for converting to the mediawiki, it is ok.
But if there ar more the it is great deal of time and effort.
For autom. Imageupload the only working solution was the discontinued project Word2MediaWikiPlus.
If somethings has changed in the last years let it me now.
But if not there are some solutions with work without image upload
(if I found them i will add these entry here):
- on webserer projekt which generated very good wiki markup output there , i can' t remember the name.
- a commandline tool that do the conversion as input and output file