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

parseexcelfile

v1.0.6

Published

A library to parse Excel files and extract text and images

Readme

parseexcelfile

一个用于解析Excel文件并提取其中文本和图片的JavaScript库,图片必须是嵌入单元格的图,浮动的图片是不能解析的哦。

特性

  • 从Excel文件中提取文本和图片
  • 支持CommonJS、ES Modules和浏览器环境
  • 提供完整的TypeScript类型定义
  • 兼容Node.js和浏览器环境

安装

npm install parseexcelfile

使用方法

在 ES Modules 环境中

import { parseExcelFile } from 'parseexcelfile';

// 从文件输入获取文件
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  try {
    const result = await parseExcelFile(file);
    console.log(result);
    // 处理解析结果...
  } catch (error) {
    console.error("解析失败:", error);
  }
});

在 CommonJS 环境中

const { parseExcelFile } = require('parseexcelfile');

// 读取Excel文件
const fs = require('fs');
const path = require('path');

async function main() {
  // 读取文件
  const fileBuffer = fs.readFileSync(path.resolve(__dirname, 'example.xlsx'));
  
  // 创建类似浏览器 File 对象的接口
  const file = {
    arrayBuffer: async () => fileBuffer
  };
  
  try {
    const result = await parseExcelFile(file);
    console.log(result);
  } catch (error) {
    console.error("解析失败:", error);
  }
}

main();

在浏览器中通过 <script> 标签使用

<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
<script src="https://unpkg.com/parseexcelfile/dist/browser/parseexcelfile.min.js"></script>
<script>
  // 从文件输入获取文件
  const fileInput = document.getElementById('fileInput');
  fileInput.addEventListener('change', async (e) => {
    const file = e.target.files[0];
    try {
      const result = await parseexcelfile.parseExcelFile(file);
      console.log(result);
      // 处理解析结果...
    } catch (error) {
      console.error("解析失败:", error);
    }
  });
</script>

API

parseExcelFile(file, sliceNum = 1)

解析Excel文件并提取其中的数据和图片。

  • file: 包含Excel文件数据的对象,必须有arrayBuffer()方法
  • sliceNum: 从结果中跳过的行数,默认为1

返回:包含文本和图片的数据数组

数据类型

// Excel行数据
interface RowData {
  // 工作表名称
  sheetName: string;
  // 行索引
  rowIndex: number;
  // 行数据
  data: any[];
  // 图像数据
  images: any[];
}

// 图像信息
interface ImageInfo {
  // 图像ID
  id: string;
  // 关系ID
  rid: string;
  // 图像名称
  name: string;
  // 图像数据URL
  dataUrl?: string;
}
- getMimeType(filename)
- blobToDataUrl(blob)
- parseRelationshipsXml(xmlDoc)
- parseCellImagesXml(xmlDoc)
- mergeImageData(jsonCellImages, jsonRelationships)
- getImageUrl(textData, allImageInfo)

## 浏览器兼容性

该库支持所有现代浏览器和IE11+(需要适当的polyfill)。浏览器版本依赖于以下全局对象:
- Promise
- FileReader
- Blob
- ArrayBuffer

## 开发

### 构建

```bash
# 安装依赖
npm install

# 构建所有版本(CommonJS、ESM、浏览器)
npm run build

# 仅构建 CommonJS 版本
npm run build:cjs


# 仅构建浏览器版本
npm run build:browser

目录结构

parseexcelfile/
├── dist/            # 构建输出目录
│   ├── browser/     # 浏览器UMD格式
│   ├── esm/         # ES Modules格式 
│   └── types/       # TypeScript类型定义
├── src/             # 源代码
│   ├── index.js     # CommonJS入口
│   └── browser.js   # 浏览器入口
├── types/           # TypeScript类型定义源文件
│   └── index.d.ts   
├── examples/        # 使用示例
└── package.json

许可证

ISC