npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

export-word-js

v1.0.0

Published

基于docxtemplater和PizZip二次封装的,一个用于将数据导出为 Word 文档的 TypeScript 类库

Readme

export-word-js

基于docxtemplaterPizZip二次封装的,一个用于将数据导出为 Word 文档的 TypeScript 类库。

简介

export-word-js是一个轻量级库,它利用 docxtemplaterPizZip 来实现前端生成 Word 文档的功能。通过简单的配置和数据输入,即可将数据渲染进预定义的 Word 模板并下载。

功能特性

  • 基于 docxtemplater 进行模板渲染。
  • 支持图片插入,并可自动调整大小。
  • 支持数据流的 base64 解码与文件下载。
  • 提供默认配置,可自定义文件名、图片尺寸等。
  • 基于angular-expressions插件,能支持自定义parser解析器

安装

使用 npm 或 yarn 安装:

npm install export-word-js
# 或者
yarn add export-word-js

使用示例

url地址可以为本地地址和服务器地址,为本地地址时,将模板文件放在public文件夹下。为服务地址时,请确保浏览器能正常下载该文档。

import Export2Word from 'export-word-js';

// 先初始化导出类
const exporter = new Export2Word({
  url: '/template.docx', // url可以为本地地址也可以为一个服务器地址,如:https://xxx.xxx.com/template.docx
  options: {
    fileName: 'output.docx',
    imgMinSize: [600, 360],
    imgMaxSize: [794, 476],
  },
});

const data = {
  // 填充的数据
};

exporter.exportToWord(data);

基础配置

options: {
   nullGetter: () => '',
   linebreaks: true,
   paragraphLoop: true,
   delimiters: { start: '{{', end: '}}' },
   imgSize: 'auto',
   imgMaxSize: [794, 476],
   imgMinSize: [600, 360],
   fileName: 'output.docx',
   parserConfig: {}, // 配置使用 angular-expressions 插件,默认是启用的,启用时,可以使用复杂的表达式,如:{{users.name}}
}

温馨提示

默认的数据标识符是以 {{ 开始和 }} 结尾

在配置docxtemplater时,可以参考官网的详细配置:docxtemplater-config

在配置parserConfig选项时,可以参考官网的详细说明: docxtemplater-angular-parse

API

new Export2Word(params: IConfig)

初始化导出工具,参数包括 Word 模板地址和导出配置。

exportToWord(data: Idata)

将数据渲染进 Word 模板并下载生成的文档。

依赖

  • docxtemplater
  • PizZip
  • docxtemplater-image-module-free
  • angular-expressions

许可证

MIT License