# excel-code-generator

> 一个能够读取 excel 文件的指定单元格并生成指定代码到文件中的工具

Latest version **2.0.3** (published 2020-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install excel-code-generator
pnpm add excel-code-generator
yarn add excel-code-generator
bun add excel-code-generator
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2020-01-12 |
| First published | 2020-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 31.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | yeyan1996 |
| Maintainers | yeyan1996 |
| Keywords | excel, node |

## Links

- npm: https://www.npmjs.com/package/excel-code-generator
- Repository: https://github.com/yeyan1996/excel-code-generator
- Homepage: https://github.com/yeyan1996/excel-code-generator#readme
- Issues: https://github.com/yeyan1996/excel-code-generator/issues
- npm.io page: https://npm.io/package/excel-code-generator

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [camelcase](https://npm.io/package/camelcase.md) ^5.3.1
- [node-xlsx](https://npm.io/package/node-xlsx.md) ^0.12.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2020-01-12
- 2.0.2 — 2020-01-12
- 2.0.1 — 2020-01-12

## README

# excel-code-generator

> 一个能够读取 excel 文件的指定单元格并生成指定代码到文件中的工具

在后台管理系统中，往往需要输入很多字段名，手动输入会造成很多隐藏的错误

`如果数据字段的文档是用 excel 写的话`，使用这款工具，用户只需配置生成的代码的模版，即可自动生成代码片段并写入指定文件中，提高工作效率，减少误差

## 使用

```
npm i excel-code-generator -D
```

```javascript
const { gen, excel } = require("excel-code-generator");

gen({
  target: "./example/index.vue",
  reg: /table>/g,
  template: excel`
     <el-table-column
        prop="${{
          source: "./example/excel.xlsx",
          line: ["H", 1, 5]
        }}"
        label="${{
          source: "./example/excel.xlsx",
          line: ["I", 1, 5]
        }}"
        width="180">
      </el-table-column>
    `
});
```

## Api

|      Name      |    类型    | Description          | 是否必填 |
| :------------: | :--------: | :------------------- | -------- |
| **`template`** | `{string}` | `生成的代码模版`     | 是       |
|  **`target`**  | `{string}` | `写入文件路径`       | 否       |
|   **`reg`**    | `{RegExp}` | `写入文件的具体位置` | 否       |

其中 excel-code-generator 为 template 提供了特殊的标签模版 `excel`，标签模版提供了一些自定义语法帮助更好的填入 excel 的值

```
excel`
     <el-table-column
        prop="${{
          source: "./example/excel.xlsx",
          line: ["H", 1, 5]
        }}"
        label="${{
          source: "./example/excel.xlsx",
          line: ["I", 1, 5]
        }}"
        width="180">
      </el-table-column>
    `
```

在 `${}` 中传入一个对象，类型如下，最后生成以下模版

Option

|      参数       |     Type     | Description                                                                          | 是否必填 |
| :-------------: | :----------: | :----------------------------------------------------------------------------------- | -------- |
|  **`source`**   |  `{string}`  | `读取的 excel 路径`                                                                  | 是       |
|   **`line`**    | `{string[]}` | `读取 Excel 的位置，第一个元素为 Excel 的列（英文索引），第二，三个元素为列的起止行` | 是       |
| **`camelcase`** | `{boolean}`  | `是否将该字段转为驼峰，默认 true`                                                    | 否       |

```vue
<el-table-column prop="I1" label="H1" width="180">
  </el-table-column>

<el-table-column prop="I2" label="H2" width="180">
  </el-table-column>

<el-table-column prop="I3" label="H3" width="180">
  </el-table-column>

<el-table-column prop="I4" label="H4" width="180">
  </el-table-column>

<el-table-column prop="I5" label="H5" width="180">
  </el-table-column>
```

---
_Source: https://npm.io/package/excel-code-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
