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 🙏

© 2025 – Pkg Stats / Ryan Hefner

zxkv-excel-json

v1.0.0

Published

excel to json

Readme

zxkv-excel-json

Description

前端解析 xls 和 xlsx 格式的 excel 文件数据,解析转换为 JSON 数据格式。

Install

你可以使用 yarnnpmpnpm 等包管理工具进行安装; 安装方式如下:

yarn add zxkv-excel-json

or

npm install zxkv-excel-json

or

pnpm add zxkv-excel-json

Using

引入方式:

import {
	v_xls,
	v_xlsx,
	v_excel
} from "zxkv-excel-json";

methods

| 方法 | 介绍 | | ------- | ------------------------------ | | v_xls | xls 格式的 excel 文件数据解析 | | v_xlsx | xlsx 格式的 excel 文件数据解析 | | v_excel | xls 和 xlsx 格式的文件数据解析 |

[excel文件数据解析] - 固定列表项

/**
 * @description xls、xlsx 转 json
 * @param {Object} file 本地文件对象
 * @return {Object}  解析成功时返回 Array 类型的数组,解析失败时 返回 null
 * 注:非 excel 文件会解析失败,返回 null
 */
const parseJSON = async file => {
	// key: 数据表头列表项、prop:对应匹配的键值
	let stmpKeys = {
		姓名: {
			prop: "stuName",
			type: String
		},
		性别: {
			prop: "stuSix",
			type: String
		},
		学号: {
			prop: "stuNo",
			type: Number
		}
	};
	// 注:列表项需唯一

	// 数据项默认值
	let stmpVals = {
		stuName: "",
		stuSix: "",
		stuNo: ""
	};

	// 列表表头前的描述所占行数,默认 0,即:head 在第一行
	let descValue = 0;

	// 方法 1:当前方式仅支持 xls 格式的 excel 文件解析
	let list1 = await v_xls(file, stmpKeys, stmpVals, descValue);

	// 方法 2:当前方式仅支持 xlsx 格式的 excel 文件解析
	let list2 = await v_xlsx(file, stmpKeys, stmpVals, descValue);

	// 方法 3:当前方法支持 xls 和 xlsx 两种格式的 excel 文件解析
	let list3 = await v_excel(file, stmpKeys, stmpVals, descValue);

	if (Array.isArray(list)) {
		// 解析成功
		console.log("文件解析成功");
	} else {
		// 解析失败
		console.warn("文件解析失败");
	}
};

[数据格式] - 固定项

[
	{
		stuName: "小明",
		stuSix: "男",
		stuNo: "stu001"
	},
	{
		stuName: "小红",
		stuSix: "女",
		stuNo: "stu002"
	},
	......
];

[excel文件数据解析] - 动态列表项

/**
 * @description xls、xlsx 转 json
 * @param {Object} file 本地文件对象
 * @return {Object}  解析成功时返回 Array 类型的数组,解析失败时 返回 null
 * 注:非 excel 文件会解析失败,返回 null
 */
const parseJSON = async file => {
	// 列表项不固定
	let stmpKeys = {};

	// 数据项默认值
	let stmpVals = {};

	// 列表表头前的描述所占行数,默认 0,即:head 在第一行
	let descValue = 0;

	// 方法 1:当前方式仅支持 xls 格式的 excel 文件解析
	let data1 = await v_xls(file, {}, {}, descValue, true);

	// 方法 2:当前方式仅支持 xlsx 格式的 excel 文件解析
	let data2 = await v_xlsx(file, {}, {}, descValue, true);

	// 方法 3:当前方法支持 xls 和 xlsx 两种格式的 excel 文件解析
	let data3 = await v_excel(file, {}, {}, descValue, true);

	//  数据方式三选一
	let data = data1 || data2 || data3;
	/**
	 * head:表头
	 * 格式:['姓名','性别','学号']
	 * body:数据体
	 * 格式:[['小明','男',null],['小红','女','stu001']]
	 **/
	let { head, body } = data;
	// ... 依据返回数据处理成符合自己要求的数据格式即可
};

Ends

⏰ tips:基于 Demo 案例重新构建,有好的建议或使用过程中发现问题,可邮件联系。

📮 email:[email protected]