纯前端实现结构描述生成Word文件
struct-to-docx
基于 docx 库的结构描述生成 .docx 文件引擎。支持浏览器和 node.js 环境下使用。
<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>
详细示例参考 test 目录下的 test.html
分情破爱始乱弃,流落天涯思别离。
如花似玉负情意,影如白昼暗自迷。
随风浮沉千叶落,行色匆匆鬓已稀。

浙公网安备 33010602011771号