Skip to content

🌸 A cli can automatically generate files from Excel files.

License

Notifications You must be signed in to change notification settings

sudongyuer/unxlsx

Repository files navigation

unxlsx

A cli can automatically generate files from Excel files.

NPM version

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

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
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 <fileName>.ts

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

import EnTranslate, { EnTranslateKeys, getEnTranslate } from '@/constant/EnTranslate'

//...
return (
    <>
      {/* normal use */}
      <p>
        {getEnTranslate(EnTranslateKeys.xxx1)}
      </p>
      {/* use slot */}
      <p>
        {getEnTranslate(EnTranslateKeys.xxx2, 'slot1', 'slot2')}
      </p>
    </>
)

Author

sudongyuer email:976499226@qq.com

License

MIT License © 2021 SuDongYu