伺服器無 LibreOffice/OnlyOffice 環境時,可借助第三方文件轉換 API 實現 Office 文件線上預覽。本文介紹百度百會 GeGe 遠端文件 API 的接入方式。
apikey。https://gege.baihui.com/remotedoc.im。output=editor 獲取可編輯預覽頁,或 output=html 獲取靜態 HTML。<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>測試百會遠端 API</title></head>
<body>
<form action="https://gege.baihui.com/remotedoc.im?apikey=你的KEY&output=editor"
target="_self" enctype="multipart/form-data" method="post">
上傳文件: <input type="file" name="content" />
<input type="hidden" name="filename" value="my.xls,my.xlsx" />
<input type="hidden" name="saveurl" value="https://your.com/callback" />
<input type="hidden" name="id" value="21012145" />
<input type="hidden" name="format" value="xlsx" />
<input type="hidden" name="persistence" value="true" />
<input type="submit" value="提交預覽" />
</form>
</body>
</html>
將 format 改為 docx,filename 包含 doc,docx 即可。
| 參數 | 說明 |
|---|---|
| apikey | 開發者金鑰,免費額度有限制 |
| output | editor=可編輯預覽, html=靜態 HTML, pdf=PDF 輸出 |
| saveurl | 編輯保存後回調 URL,接收轉換結果 |
| persistence | true=持久化儲存, false=臨時 |