Methods
(async) WDocx2html(fpIn, fpOut, optopt) → {Promise}
- Description:
以Microsoft Word將Docx檔轉為Html檔
- Source:
Example
import w from 'wsemi'
import WDocx2html from './src/WDocx2html.mjs'
//import WDocx2html from 'w-docx2html/src/WDocx2html.mjs'
//import WDocx2html from 'w-docx2html'
async function test() {
let fpIn = `./test/docin.docx`
let fpOut = `./test/docout.html`
let opt = {
execFontGrow: 1,
}
let r = await WDocx2html(fpIn, fpOut, opt)
console.log(r)
// => ok
w.fsDeleteFile(fpOut)
}
test()
.catch((err) => {
console.log('catch', err)
})
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fpIn |
String | 輸入來源Docx檔位置字串 |
||||||||||||
fpOut |
String | 輸入轉出Html檔位置字串 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise,resolve回傳成功訊息'ok',reject回傳錯誤訊息。reject值有下列型態:參數檢測失敗為說明字串;取不到執行檔為[code] 訊息字串(code取自ensureBins,如[E_OFFLINE_MISSING] ...);docx2html.exe無法執行或離開碼非0為execProcess之訊息字串(如code[N]:\n...);docx2html.exe執行後自報失敗(如輸入非docx、docx損毀、Word無法開啟或無法另存)為[E_CONVERT_FAILED] 原因,原因為exe輸出之診斷(已依系統字碼頁解碼,不回顯輸入與輸出路徑,但Word之診斷可能自行含檔名);exe報成功而fpOut未產生或為空檔(如fpOut無副檔名,Word另存為<fpOut>.htm)亦為[E_CONVERT_FAILED] output file was not generated or is empty。docx2html.exe不論成敗離開碼皆為0,故以其輸出判定成敗:須有success行且無error:行才resolve,空輸出或未知輸出亦視為失敗;失敗(reject)時fpOut之內容不可採用,本套件不刪除fpOut既有之舊檔
- Type
- Promise
(async) autoDownloadFiles() → {Promise}
- Description:
取得docx2html.exe,回傳docx2html.exe的絕對路徑
相容層:本檔為舊版對外介面,內部改經ensureBins取得,依bin/manifest.json之SHA-256與大小校驗, 首次使用時下載(或自鏡像取得),之後自快取取得,不再偵測當前工作路徑之src/與node_modules/w-docx2html/src/, 環境變數W_BIN_CACHE、W_BIN_MIRROR、W_BIN_OFFLINE見README〈外部執行檔〉
因docx2html.exe只能用於Windows作業系統,故調用前須自行檢核作業系統
- Source:
Example
import autoDownloadFiles from 'w-docx2html/src/autoDownloadFiles.mjs'
async function test() {
//autoDownloadFiles, 取得docx2html.exe, 取得失敗則reject
let { fpExe } = await autoDownloadFiles()
console.log('fpExe', fpExe)
// fpExe D:\xxx\node_modules\w-docx2html\bin-cache\<sha256>\docx2html.exe
}
test()
.catch((err) => {
console.log('catch', err)
})
Returns:
回傳Promise,resolve回傳執行檔路徑物件,內含fpExe為docx2html.exe的絕對路徑字串,reject回傳帶code之Error(E_OFFLINE_MISSING等)
- Type
- Promise
ensureBins(optopt) → {Promise}
- Description:
取得本套件之外部執行檔docx2html.exe: 首次使用時下載(或自鏡像取得)並以bin/manifest.json之SHA-256與大小校驗, 之後自快取取得(亦校驗)
規格: 外部執行檔之存放下載校驗與離線(制式規格)§6; 實作為wsemi之fsEnsureBins, 本套件不另寫下載、快取、鏡像、校驗 環境變數: W_BIN_CACHE(共用快取資料夾)、W_BIN_MIRROR(鏡像, 本地資料夾或http(s)網址)、W_BIN_OFFLINE(1為離線), 見README〈外部執行檔〉
- Source:
Example
import ensureBins from 'w-docx2html/src/ensureBins.mjs'
async function test() {
//部署前預先取得, 離線部署見README〈外部執行檔〉
let bins = await ensureBins()
console.log(bins['docx2html.exe'])
// => D:\xxx\node_modules\w-docx2html\bin-cache\<sha256>\docx2html.exe
}
test()
.catch((err) => {
console.log('catch', err)
})
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件, 交wsemi之fsEnsureBins(names、cacheDir、mirror、offline、onProgress等), pkgRoot固定為本套件根 |
Returns:
回傳Promise, resolve回傳{ [檔名]: 絕對路徑 }, reject回傳帶code之Error(E_OFFLINE_MISSING等)
- Type
- Promise