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

vue-table-print

v1.0.6

Published

一个强大的Vue表格打印工具,支持ElementPlus、Ant Design Vue、Arco Design vue等组件库

Readme

vue-table-print

npm version downloads license

一个强大的Vue 3表格打印工具,支持ElementPlus、Ant Design Vue等主流UI组件库。

特性

  • 🚀 Vue 3 + TypeScript - 完整的类型支持
  • 📱 响应式设计 - 适配不同屏幕和打印尺寸
  • 🎨 高度可定制 - 支持自定义样式、水印、Logo等
  • 📄 多种导出格式 - 支持打印、预览、导出HTML
  • 🔧 灵活配置 - 丰富的配置选项满足不同需求
  • 📦 轻量级 - 零依赖,体积小巧
  • 🎯 易于使用 - 简单的API设计,快速上手

安装

# npm
npm install vue-table-print

# yarn
yarn add vue-table-print

# pnpm
pnpm add vue-table-print

快速开始

基础用法

<template>
  <div>
    <el-button @click="handlePrint">打印表格</el-button>
    <el-table :data="tableData">
      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="age" label="年龄" />
      <el-table-column prop="department" label="部门" />
    </el-table>
  </div>
</template>

<script setup>
import { useTablePrint } from 'vue-table-print'

const { printTable } = useTablePrint({
  title: '员工信息表'
})

const tableData = [
  { name: '张三', age: 28, department: '技术部' },
  { name: '李四', age: 32, department: '产品部' }
]

const columns = [
  { prop: 'name', label: '姓名' },
  { prop: 'age', label: '年龄', align: 'center' },
  { prop: 'department', label: '部门' }
]

const handlePrint = async () => {
  const result = await printTable(tableData, columns)
  if (!result.success) {
    console.error('打印失败:', result.message)
  }
}
</script>

类实例用法

import { TablePrintUtil } from 'vue-table-print'

const printUtil = new TablePrintUtil({
  title: '数据报表',
  pageSize: 'A4',
  orientation: 'landscape'
})

// 打印表格
await printUtil.printTable(data, columns)

// 预览表格
printUtil.previewTable(data, columns)

// 导出HTML
printUtil.exportToHTML(data, columns, 'report.html')

API参考

PrintOptions 配置选项

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | title | string | '数据表格' | 打印标题 | | showHeader | boolean | true | 是否显示页头 | | showFooter | boolean | true | 是否显示页脚 | | pageSize | 'A4' | 'A3' | 'A5' | 'Letter' | 'A4' | 页面尺寸 | | orientation | 'portrait' | 'landscape' | 'portrait' | 页面方向 | | margins | string | '1cm' | 页面边距 | | fontSize | string | '12px' | 字体大小 | | headerStyle | object | - | 表头样式配置 | | customStyles | string | '' | 自定义CSS样式 | | watermark | string | '' | 水印文字 | | logo | string | '' | Logo图片URL |

TableColumn 列配置

| 参数 | 类型 | 说明 | |------|------|------| | prop | string | 数据字段名 | | label | string | 列标题 | | align | 'left' | 'center' | 'right' | 对齐方式 | | width | number | string | 列宽度 | | formatter | function | 格式化函数 |

方法

useTablePrint(options?)

组合式函数,返回打印相关方法。

const { printTable, previewTable, exportToHTML } = useTablePrint(options)

printTable(data, columns, options?)

打印表格数据。

  • data: any[] - 表格数据
  • columns: TableColumn[] - 列配置
  • options: Partial<PrintOptions> - 可选配置
  • 返回: Promise<PrintResult> - 打印结果

previewTable(data, columns, options?)

预览表格打印效果。

exportToHTML(data, columns, filename?, options?)

导出为HTML文件。

高级用法

自定义格式化

const columns = [
  {
    prop: 'salary',
    label: '薪资',
    align: 'right',
    formatter: (row, column, value) => `¥${value.toLocaleString()}`
  },
  {
    prop: 'status',
    label: '状态',
    formatter: (row) => row.status === 1 ? '在职' : '离职'
  }
]

添加水印和Logo

const { printTable } = useTablePrint({
  title: '机密文档',
  watermark: '内部资料',
  logo: '/path/to/company-logo.png'
})

自定义样式

const customOptions = {
  customStyles: `
    .print-table th {
      background-color: #1890ff !important;
      color: white !important;
    }
    .print-table td {
      border-color: #1890ff !important;
    }
  `
}

await printTable(data, columns, customOptions)

横向打印大表格

await printTable(data, columns, {
  orientation: 'landscape',
  pageSize: 'A3',
  fontSize: '10px'
})

浏览器兼容性

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

常见问题

Q: 为什么打印窗口被拦截?

A: 现代浏览器会拦截弹窗,请允许当前网站的弹窗权限。

Q: 如何自定义打印样式?

A: 使用 customStyles 选项添加自定义CSS,或通过 headerStyle 配置表头样式。

Q: 支持哪些UI组件库?

A: 本库是UI组件库无关的,支持ElementPlus、Ant Design Vue、Naive UI等所有Vue 3组件库。

贡献

欢迎提交 Issue 和 Pull Request!

License

MIT License

更新日志

v1.0.6

  • 🎉 首次发布
  • ✨ 支持基础打印功能
  • ✨ 支持预览和导出HTML
  • ✨ 完整的TypeScript支持