An open API service indexing awesome lists of open source software.

https://github.com/sudongyuer/unxlsx

🌸 A cli can automatically generate files from Excel files.
https://github.com/sudongyuer/unxlsx

cli excel generator xlsx

Last synced: over 1 year ago
JSON representation

🌸 A cli can automatically generate files from Excel files.

Awesome Lists containing this project

README

          

# unxlsx

A cli can automatically generate files from Excel files.

[![NPM version](https://img.shields.io/github/package-json/v/sudongyuer/unxlsx)](https://www.npmjs.com/package/unxlsx)



## Why

We often need to export some information from `XLSX` to generate our files, such as `multi-language`, such as `error message copywriting`, such as project `translation copywriting`, when we need `unxlsx` to help us automatically generate

## Features

- Multiple xlsx support
- Custom filed key support
- Custom filed value support
- Automatic generation of files if the file does not exist
- Typescript support config file
- ✨ support `{}` slot in the filed value

## Usage

### Install

```bash
pnpm add -D unxlsx
```

### Config `generate.config.ts`

- xlsxDir (require) : xlsx file directory base on `process.cwd()`

- files (require) : all the files you want to generate
- key (require) : the key in the xlsx file
- value (require) : the value in the xlsx file
- outPutFileDir (require) : the file you want to generate to

```js
import { defineGenerateConfig } from 'unxlsx/utils'
export default defineGenerateConfig({
xlsxDirs: [
{
xlsxDir: './xxx1.xlsx',
files: [
{
key: 'key1',
value: 'value1',
outPutFileDir: './src/generate/file1.ts',
},
{
key: 'key2',
value: 'value2',
outPutFileDir: './src/generate/file2.ts',
},
],
},
{
xlsxDir: './xxx2.xlsx',
files: [
{
key: '后端接口错误码',
value: '中文文案对照',
outPutFileDir: './src/generate/file3.ts',
},
{
key: '后端接口错误码',
value: '英文文案',
outPutFileDir: './src/generate/file4.ts',
},
],
},
],
})
```

### Generate `.ts`

```bash
pnpm run unxlsx
```

### UseSlot Demo
- `EnTranslate` was the object that describes the information in the xlsx file
- `EnTranslateKeys` was the array that describes the `EnTranslate` keys
- `getEnTranslate` you can get the value you want to use in the file
- `@/constant/EnTranslate` was the directory of the generated file directory
- above code all generated by unxlsx

`In react jsx`
```jsx
import EnTranslate, { EnTranslateKeys, getEnTranslate } from '@/constant/EnTranslate'

//...
return (
<>
{/* normal use */}


{getEnTranslate(EnTranslateKeys.xxx1)}


{/* use slot */}


{getEnTranslate(EnTranslateKeys.xxx2, 'slot1', 'slot2')}


>
)
```

## Author

sudongyuer email:976499226@qq.com

## License

[MIT](./LICENSE) License © 2021 [SuDongYu](https://github.com/sudongyuer)