純前端實(shí)現(xiàn)結(jié)構(gòu)描述生成Word文件
struct-to-docx
基于 docx 庫(kù)的結(jié)構(gòu)描述生成 .docx 文件引擎。支持瀏覽器和 node.js 環(huán)境下使用。
<script setup lang="ts">
import { DocxBuilder } from "struct-to-docx"
function generateDocx() {
const builder = new DocxBuilder()
const doc = builder.addSection({
children: [
{
type: "paragraph",
options: {
alignment: "center",
children: [
{
type: "text",
options: {
bold: true,
color: "FF0000",
font: "Arial",
size: DocxBuilder.textSize(12),
field: "textField"
}
}
]
}
}
]
}).render({
textField: "This is bold and red text."
})
builder.fileSave(doc, "example.docx")
}
</script>
<template>
<div>
<button @click="generateDocx">
Generate DOCX
</button>
</div>
</template>
<style lang="scss" scoped></style>
詳細(xì)示例參考 test 目錄下的 test.html
分情破愛始亂棄,流落天涯思別離。
如花似玉負(fù)情意,影如白晝暗自迷。
隨風(fēng)浮沉千葉落,行色匆匆鬢已稀。

浙公網(wǎng)安備 33010602011771號(hào)