@flatfile/plugin-xlsx-extractor

中文文档
4.1.1发布于 2025/10/18ISCTypeScriptESM + CJS近 30 天下载 6.4万

A plugin for parsing xlsx files in Flatfile.

原始使用文档
文档目录5 节
  1. Parameters
  2. API Calls
  3. Usage
  4. Header Detection
  5. Full Example

The @flatfile/plugin-xlsx-extractor plugin is designed to extract structured data from Excel files. It utilizes various libraries to parse Excel files and retrieve the structured data efficiently.

Event Type: listener.on('file:created')

Supported file types: .xls, .xlsx, .xlsm, .xlsb, .xltx, .xltm

When embedding Flatfile, this plugin should be deployed in a server-side listener. Learn more

Parameters

raw - boolean

In Excel, you could have formatting on a text cell (i.e. date formatting). By default, Flatfile will just take the formatted text versus the raw values. Set this value to true to take the raw values and disregard how it's displayed in Excel.

rawNumbers - boolean

In Excel, you could have rounding or formatting on a number cell to only display say 2 decimal places. By default, Flatfile will just take the displayed decimal places versus the raw numbers. Set this value to true to take the raw numbers and disregard how it's displayed in Excel.

dateNF - string - (optional)

The dateNF parameter allows you to specify the date format for parsing dates. (i.e. yyyy-mm-dd)

chunkSize - default: "10_000" - number - (optional)

The chunkSize parameter allows you to specify the quantity of records to in each chunk.

parallel - default: "1" - number - (optional)

The parallel parameter allows you to specify the number of chunks to process in parallel.

headerDetectionOptions - Object - (optional)

The headerDetectionOptions parameter allows you to specify the options for detecting headers in the file. By default, the first 10 rows are scanned for the row with the most non-empty cells.

skipEmptyLines - default: "false" - boolean - (optional)

The skipEmptyLines parameter allows you to specify if empty lines should be skipped. By default, empty lines are included.

debug - default: "false" - boolean - (optional)

The debug parameter lets you toggle on/off helpful debugging messages for development purposes.

cascadeRowValues - default: "false" - boolean - (optional)

The cascadeRowValues parameter automatically cascades values down the dataset until a blank row, new value, or end of dataset. This is useful for hierarchical data where values in a column apply to multiple rows below them.

cascadeHeaderValues - default: "false" - boolean - (optional)

The cascadeHeaderValues parameter automatically cascades values across the header rows until a blank column, new value, or end of dataset. This is useful for multi-level headers where a header value applies to multiple columns.

mergedCellOptions - Object - (optional)

The mergedCellOptions parameter allows you to specify how merged cells should be handled during extraction. You can define different treatments for cells merged across columns, rows, or ranges.

Merged Cell Vectors
  • acrossColumns: Applies to cells merged horizontally (across multiple columns in the same row)
  • acrossRows: Applies to cells merged vertically (across multiple rows in the same column)
  • acrossRanges: Applies to cells merged both horizontally and vertically (across multiple rows and columns)
Treatment Options

For all vectors:

  • applyToAll: Applies the merged cell value to all cells in the un-merged range
  • applyToTopLeft: Applies the merged cell value only to the top-left cell in the un-merged range

For acrossColumns and acrossRows only:

  • coalesce: Keeps only the first row/column and removes other rows/columns
  • concatenate: Combines values from all cells using a separator (requires separator parameter)

Example configuration:

mergedCellOptions: {
  acrossColumns: {
    treatment: 'concatenate',
    separator: ', '
  },
  acrossRows: {
    treatment: 'applyToAll'
  },
  acrossRanges: {
    treatment: 'applyToTopLeft'
  }
}

API Calls

  • api.files.download
  • api.files.get
  • api.files.update
  • api.jobs.ack
  • api.jobs.complete
  • api.jobs.create
  • api.jobs.fail
  • api.jobs.update
  • api.records.insert
  • api.workbooks.create

Usage

Listen for an Excel file (all extensions supported) to be uploaded to Flatfile. The platform will then extract the file automatically. Once complete, the file will be ready for import in the Files area.

npm i @flatfile/plugin-xlsx-extractor
import { ExcelExtractor } from "@flatfile/plugin-xlsx-extractor";

listener.js

listener.use(ExcelExtractor());

Additional options

listener.use(ExcelExtractor({ 
  raw: true, 
  rawNumbers: true,
  cascadeRowValues: true,
  cascadeHeaderValues: true,
  mergedCellOptions: {
    acrossColumns: {
      treatment: 'concatenate',
      separator: ', '
    },
    acrossRows: {
      treatment: 'applyToAll'
    },
    acrossRanges: {
      treatment: 'applyToTopLeft'
    }
  }
}));

Header Detection

Three detection options are provided for detecting headers in the file: default, explicitHeaders, and specificRows. By default, the first 10 rows are scanned for the row with the most non-empty cells. This row is then used as the header row.

Default

It looks at the first rowsToSearch rows and takes the row with the most non-empty cells as the header, preferring the earliest such row in the case of a tie.

listener.use(ExcelExtractor());
// or...
listener.use(
  ExcelExtractor({
    headerDetectionOptions: {
      algorithm: "default",
      rowsToSearch: 30, // Default is 10
    },
  })
);

Explicit Headers

This implementation simply returns an explicit list of headers it was provided with.

listener.use(
  ExcelExtractor({
    headerDetectionOptions: {
      algorithm: "explicitHeaders",
      headers: ["fiRsT NamE", "LaSt nAme", "emAil"],
    },
  })
);

Specific Rows

This implementation looks at specific rows and combines them into a single header. For example, if you knew that the header was in the third row, you could pass it { rowNumbers: [2] }.

listener.use(
  ExcelExtractor({
    headerDetectionOptions: {
      algorithm: "specificRows",
      rowNumbers: [2], // 0 based
    },
  })
);

Data Row & Sub Header Detection

This implementation attempts to detect the first data row and select the previous row as the header. If the data row cannot be detected due to all the sample rows being full and not castable to a number or boolean type, it also will attempt to detect a sub header row by checking following rows after a header is detected for significant fuzzy matching. If over half of the fields in a possible sub header row fuzzy match with the originally detected header row, the sub header row becomes the new header.

listener.use(
  ExcelExtractor({
    headerDetectionOptions: {
      algorithm: "dataRowAndSubHeaderDetection",
      rowsToSearch: 30, // Default is 10
    },
  })
);

Full Example

In this example, the ExcelExtractor is initialized with optional options, and then registered as middleware with the Flatfile listener. When an Excel file is uploaded, the plugin will extract the structured data and process it using the extractor's parser.

listener.js

import { ExcelExtractor } from "@flatfile/plugin-xlsx-extractor";

export default async function (listener) {
  // Define optional options for the extractor
  const options = {
    raw: true,
    rawNumbers: true,
    cascadeRowValues: true,
    cascadeHeaderValues: true,
  };

  // Initialize the Excel extractor
  const excelExtractor = ExcelExtractor(options);

  // Register the extractor as a middleware for the Flatfile listener
  listener.use(excelExtractor);

  // When an Excel file is uploaded, the data will be extracted and processed using the extractor's parser.
}

版本与发布记录

@flatfile/plugin-xlsx-extractor 共发布 84 个版本,首次发布于 2023/02/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.1.1latest2025/10/181.1 年前
4.1.02025/10/181.1 年前
4.0.92025/08/281.2 年前
4.0.82025/08/271.2 年前
4.0.72025/08/181.2 年前
4.0.62025/08/011.3 年前

关于 @flatfile/plugin-xlsx-extractor 的常见问题

@flatfile/plugin-xlsx-extractor 是什么?

A plugin for parsing xlsx files in Flatfile.

如何安装 @flatfile/plugin-xlsx-extractor?

在项目目录运行 npm install @flatfile/plugin-xlsx-extractor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@flatfile/listener(^1.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flatfile/plugin-xlsx-extractor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flatfile/plugin-xlsx-extractor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flatfile/plugin-xlsx-extractor 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flatfile/plugin-xlsx-extractor 可以商用吗?

@flatfile/plugin-xlsx-extractor 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flatfile/plugin-xlsx-extractor 的下载量有多少?

根据 npm 官方下载统计,@flatfile/plugin-xlsx-extractor 在 2026/10/15 – 2026/11/13 这 30 天内被下载 64,308 次,日均约 2,144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flatfile/plugin-xlsx-extractor 还在维护吗?

最新版本 4.1.1 发布于 2025/10/18(1.1 年前);至今共发布 84 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。