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

@oiij/xlsx

v0.0.16

Published

A Vue Composable for xlsx

Readme

@oiij/xlsx

NPM version MIT-license

简介

Use XLSX 是基于 SheetJS 的工具库,提供 Excel/CSV 文件的导入、导出和数据转换功能,帮助开发者在浏览器端处理电子表格文件。

特点

📊 多格式支持

  • 📋 支持导出 XLS、XLSX、CSV 格式
  • 🔄 支持 JSON 数据转换
  • ⚙️ 支持自定义列配置

🔄 数据转换

  • 🔧 支持数据格式化和转换
  • 🛠️ 支持自定义转换函数
  • 🎯 支持类型安全的泛型

🔒 类型安全

  • 📝 完整的 TypeScript 类型定义
  • 💡 提供准确的类型推断和代码提示

安装

# 使用 pnpm
pnpm add @oiij/xlsx

# 使用 npm
npm install @oiij/xlsx

# 使用 yarn
yarn add @oiij/xlsx

依赖

  • xlsx: ^0.18.0
  • file-saver: ^2.0.0

示例

基础使用

import { exportSheet } from '@oiij/xlsx'

const data = [
  ['姓名', '年龄'],
  ['张三', 18],
  ['李四', 20]
]

exportSheet(data, '人员信息', 'xlsx')

使用列配置

import { json2Sheet } from '@oiij/xlsx'

const data = [
  { name: '张三', age: 18, gender: '男' },
  { name: '李四', age: 20, gender: '女' }
]

const columns = [
  { key: 'name', title: '姓名' },
  { key: 'age', title: '年龄' },
  { key: 'gender', title: '性别' }
]

json2Sheet(data, columns, '人员信息', 'xlsx')

数据转换

import { transform } from '@oiij/xlsx'

const data = [
  { name: '张三', age: 18, gender: '男' },
  { name: '李四', age: 20, gender: '女' }
]

const columns = [
  { key: 'name', title: '姓名' },
  { key: 'age', title: '年龄' },
  {
    key: 'gender',
    title: '性别',
    transform: ({ rawValue }) => rawValue === '男' ? '男性' : '女性'
  }
]

const result = transform(data, columns)
// 结果: [['姓名', '年龄', '性别'], ['张三', 18, '男性'], ['李四', 20, '女性']]

API

transform(data, columns)

将 JSON 数据转换为表格格式。

参数

| 参数 | 类型 | 说明 | | --------- | ------------------- | ------------- | | data | T[] | JSON 数据数组 | | columns | SheetColumns<T>[] | 列配置数组 |

返回值

| 类型 | 说明 | | --------- | ---------------- | | any[][] | 转换后的表格数据 |

exportSheet(data, fileName, type?)

导出表格文件。

参数

| 参数 | 类型 | 默认值 | 说明 | | ---------- | -------------------------- | ------- | -------- | | data | any[] | - | 表格数据 | | fileName | string | - | 文件名 | | type | 'xls' \| 'xlsx' \| 'csv' | 'xls' | 文件类型 |

json2Sheet(data, columns, fileName, type?)

将 JSON 数据导出为表格文件。

参数

| 参数 | 类型 | 默认值 | 说明 | | ---------- | -------------------------- | ------- | ------------- | | data | T[] | - | JSON 数据数组 | | columns | SheetColumns<T>[] | - | 列配置数组 | | fileName | string | - | 文件名 | | type | 'xls' \| 'xlsx' \| 'csv' | 'xls' | 文件类型 |

json2XLS(data)

将 JSON 数据转换为 XLS 文件 Blob。

json2XLSX(data)

将 JSON 数据转换为 XLSX 文件 Blob。

json2CSV(data)

将 JSON 数据转换为 CSV 文件 Blob。

SheetColumns 配置

| 选项 | 类型 | 说明 | | ----------- | ------------------- | ------------ | | key | keyof T | 数据键 | | title | string | 列标题 | | transform | (params) => value | 数据转换函数 |

Transform 参数

| 参数 | 类型 | 说明 | | ------------- | ----------------- | ---------- | | rawValue | T[key] | 原始值 | | rawRow | T | 原始行数据 | | rawRowIndex | number | 原始行索引 | | columns | SheetColumns<T> | 列配置 | | headIndex | number | 列索引 |

类型定义

export type SheetColumns<T extends Record<string, any>> = {
  key: keyof T
  title: string
  transform?: SheetTransform<T>
}

export type SheetTransformParam<T extends Record<string, any>> = {
  rawValue: T[SheetColumns<T>['key']]
  rawRow: T
  rawRowIndex: number
  columns: SheetColumns<T>
  headIndex: number
}

export declare function transform<T extends Record<string, any>>(data: T[], columns: SheetColumns<T>[]): any[][]
export declare function exportSheet(data: any[], fileName: string, type?: 'xls' | 'xlsx' | 'csv'): void
export declare function json2Sheet<T extends Record<string, any>>(data: T[], columns: SheetColumns<T>[], fileName: string, type?: 'xls' | 'xlsx' | 'csv'): void
export declare function json2XLS(data: any[]): Blob
export declare function json2XLSX(data: any[]): Blob
export declare function json2CSV(data: any[]): Blob

在线文档

在线文档