It seems you are looking for better compatibility with Microsoft Office. Google Docs is used in the browser. So, this is perfectly compatible between Windows and Ubuntu. Libreoffice has versions for both Windows and Ubuntu, again perfect compatibility.
Office Online preserves Microsoft Office .docx and other document type formatting perfectly. Therefore, I posted this question in order to automate the following steps.
Prepend this: https://view.officeapps.live.com/op/view.aspx?src=
Append the URL of the Word document:
https://dl.dropboxusercontent.com/u/4992179/My-Document.docx
Final product:
https://view.officeapps.live.com/op/view.aspx?src=https://dl.dropboxusercontent.com/u/4992179/My-Document.docx
I recommend following the steps at my forum post to keep MS Office formatting consistent in Ubuntu.
At times I receive a .docx file from a colleague that needs editing. I open it in LibreOffice to make my edits of the content (no formatting changes though) and save it. In LibreOffice the formatting will likely be different than if it were opened in MS Office. Then I open it using the Office Online script (posted below). In Office Online the formatting will be preserved, but with the recent edits I just made. Please note that if you open the same document more than once in Office Online, the second time you will need to change the file name by at least one character. The MS Office Online cache prevents it from detecting that it is indeed an updated document.
The script below can integrate into the context menu of any file manager. If you want to use terminal, you can do the following.
- Create a
bin
directory if you haven't yet in your home directory and move the script there.
cd ~/bin
- Make the script executable
chmod +x MS_Office_Online-Script
- Open a new terminal.
MS_Office_Online-Script /path/to/document.docx
In general I would try to transition to using LibreOffice instead of MS Office. In fact, I hope this script will enable you to eliminate Windows altogether. ;)
#!/bin/bash
# Name: Open in Microsoft Office Online
# Author: (c) 2015 Glutanimate <https://github.com/Glutanimate/>
# Dependencies: dropbox, a web browser (e.g. firefox, chromium...)
# Installation: https://askubuntu.com/q/574252/81372
#
# License: GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
# Usage: open_in_microsoft_office_online <file>
# Settings
DbPath="$HOME/Dropbox"
CopyToDb="yes" # whether to copy file to public dropbox folder
# in case it's not there already (no/yes)
# Variables
GuiIcon="dropbox"
GuiTitle="Open in Microsoft Office Online"
MsOfficeUrl="https://view.officeapps.live.com/op/view.aspx?src="
File="$1"
Filename="${File##*/}"
# Functions
gui_notify(){
## generic notification function
notify-send -i "$GuiIcon" "$GuiTitle" "$1"
echo "$1"
}
# Checks
## check if file selected
if [[ ! -f "$File" ]]; then
gui_notify "Error: No file selected."
exit 1
fi
## check if Dropbox running
if ! pgrep dropbox > /dev/null 2>&1; then
gui_notify "Error: Dropbox isn't running."
exit 1
fi
## check if Dropbox folder set correctly
if [[ ! -d "$DbPath" ]]; then
gui_notify "Error: Can't find dropbox folder. Please set DbPath in script."
exit 1
fi
# Main
## get public URL
DbPubUrl="$(dropbox puburl "$File")"
## optional: copy file to public dropbox folder if it isn't there
if [[ "$CopyToDb" = "yes" && "$DbPubUrl" = "Couldn't get public url: Unknown Error" ]]; then
## create public Dropbox folder if it doesn't exist
[[ ! -d "$DbPath/Public" ]] && mkdir "$DbPath/Public"
## copy file to public folder, don't overwrite any existing file
cp -n "$File" "$DbPath/Public/"
## wait for sync to complete
SyncCounter="0"
while dropbox filestatus "$DbPath/Public/$Filename" | grep syncing; do
[[ "SyncCounter" = "0" ]] && gui_notify "Syncing file..."
sleep 5
## wait a maximum of 10 minutes for sync to complete
if [[ "$SyncCounter" -gt "120" ]]; then
gui_notify "Error: Sync timeout. Exiting."
exit 1
break
fi
((SyncCounter++))
done
## get public URL
DbPubUrl="$(dropbox puburl "$DbPath/Public/$Filename")"
fi
## check if public URL exists and open in Microsoft Office Online
if [[ "$DbPubUrl" != "Couldn't get public url: Unknown Error" ]]; then
xdg-open "${MsOfficeUrl}${DbPubUrl}" > /dev/null 2>&1 &
gui_notify "Opening document in Microsoft Office Online..."
else
gui_notify "Error: Can't generate public Dropbox link from File."
fi
Below is the script that I currently use. It is actually faster than the above script (see the "Wait for sync to complete." comment), but I took out some if
statements and simplified it. Dropbox no longer has the Public folder for free accounts and discontinues it for paid ones on September 1, 2017. So, you'll need to use a different website service. You would adjust the URL in the script with your own web URL.
#!/bin/bash
# Name: Open in Microsoft Office Online
# Author: jbrock; Much thanks to Glutanimate <https://github.com/Glutanimate/>
# Dependencies: dropbox, a web browser (e.g. firefox, chromium...)
# Installation: http://askubuntu.com/q/574252/81372
# License: GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
# Usage: open_in_microsoft_office_online <file>
# Variables
pub_path="$HOME/Dropbox/Public"
file="${1##*/}"
# Copy to Dropbox/Public directory.
cp -n "$1" "$pub_path"
# Wait for sync to complete.
while dropbox filestatus "$pub_path/$file" | grep -q syncing; do true; done
# Open in browser. (Get public URL is broken: 6 Sept. 2016)
exo-open "https://view.officeapps.live.com/op/view.aspx?src=https://dl.dropboxusercontent.com/u/4992179/$file" > /dev/null 2>&1 &
# Remove file from Public folder.
# This last part is optional. You probably want to remove your document from a public directory.
# I use this function with Xfce. I am not sure about other desktop environments.
#sleep 15
#trash () {
#dir="$HOME/.local/share/Trash/files/"
#if ! [ -d "$dir" ]; then
# mkdir "$dir"
#fi
#mv "$@" "$dir"
#}
#trash "$pub_path/$file"