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 🙏

© 2024 – Pkg Stats / Ryan Hefner

zxkv-xlsx-json

v0.3.1

Published

xlsx to json

Downloads

3

Readme

zxkv-xlsx-json

Description

前端解析 xlsx 格式的 excel 文件,解析数据转换为 JSON 数据格式(仅支持 xlsx

Install

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

yarn add zxkv-xlsx-json

or

npm install zxkv-xlsx-json

or

pnpm add zxkv-xlsx-json

Using

引入方式:

import XTJ from "zxkv-xlsx-json";

methods

| 方法 | 介绍 | | ---- | ------------------------------ | | XTJ | xlsx 格式的 excel 文件数据解析 |

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

/**
 * @description 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;

	// 当前方法支持 xlsx 格式的 excel 文件解析
	let list = await XTJ(file, stmpKeys, stmpVals, descValue);

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

[数据格式] - 固定项

[
	{
		stuName: "Ming",
		stuSix: "boy",
		stuNo: "stu001"
	},
	{
		stuName: "Hong",
		stuSix: "girl",
		stuNo: "stu002"
	},
	......
];

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

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

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

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

	// 当前方式仅支持 xlsx 格式的 excel 文件解析
	let {head, body} = await XTJ(file, {}, {}, descValue, true);

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

Ends

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

📮 email:[email protected]