用于在Microsoft Office Online中查看Office文档的脚本

为了我的工作,我必须将很多Microsoft Word文档转换为PDF。 对我来说,尽可能准确地呈现格式非常重要。 我在Xubuntu 14.04上成功安装了Office 2010,但是我无法打开文档。 我只能打开一个新的空白文件。 所以,我放弃了。 然后我继续搜索Word到PDF的最准确的渲染工具。 我查看了Zamzar等在线工具以及其他选项。 (不幸的是,LibreOffice过多地改变了格式。)

经过几次测试后,我能找到的最佳渲染是:
https://view.officeapps.live.com/op/view.aspx?src=

然后,您附加Word文档的URL:
https://dl.dropboxusercontent.com/u/4992179/My-Document.docx

最终产品:
https://view.officeapps.live.com/op/view.aspx?src=https://dl.dropboxusercontent.com/u/4992179/My-Document.docx

从这里我打印到PDF。

正如您从我的链接中看到的,我会使用Dropbox的’Public’文件夹来获取我的文档的URL。 要获取公共文件夹中的URL,请右键单击该文件,然后选择“复制公共链接”。

我想尽可能简化这个过程,因为我必须做很多事情。 我想找到最好的方法。 我想创建一个运行以下内容的脚本:
chromium-browser https://view.officeapps.live.com/op/view.aspx?src= Variable-Representing-Current-Content-Of-Clipboard

单击脚本时剪贴板的当前内容将是指向Word文档文件的Dropbox链接。

(我无法为URL的https://view.officeapps.live.com/op/view.aspx?src=部分制作书签,然后只需转到地址栏并粘贴Dropbox链接,因为officeapps URL自动转发给另一个。)

如果有人有任何其他想法,我肯定对他们开放和感激。

非常感谢提前。

Nautilus脚本解决方案

抓住剪贴板内容并使用它们并不困难,但我可以做得更好。 以下Nautilus脚本将通过Microsoft Office Online打开任何支持的文档。 它是通过首先将文档复制到您的公共Dropbox文件夹(如果之前不存在)并随后将公共URL传递给Web服务来实现的:

 #!/bin/bash # Name: Open in Microsoft Office Online # Author: (c) 2015 Glutanimate  # Dependencies: dropbox, a web browser (eg 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  # 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 

组态

有两个重要的设置可以控制脚本的运行方式:

  • DbPath设置Dropbox文件夹的路径。 这是~/Dropbox默认情况下。 如果移动了DB文件夹,请务必查看设置。
  • CopyToDb控制是否将文件复制到Public文件夹(如果它们位于文件系统中的其他位置)。

    默认情况下,此选项处于启用状态( yes )。 如果禁用它( no ),脚本将只处理公共Dropbox文件夹中的文件。

安装说明

由于这是Nautilus脚本,您可以使用以下通用说明在系统上安装它:

如何安装Nautilus脚本?


希望这是你要找的!