纯前端实现结构描述生成Word文件

struct-to-docx

基于 docx 库的结构描述生成 .docx 文件引擎。支持浏览器和 node.js 环境下使用。

项目地址:GithubGitee

<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

posted @ 2025-10-28 14:02  白開水  阅读(5)  评论(0)    收藏  举报