hrms-report-template/test-run/xlsx-template.ts
2025-02-28 11:43:17 +07:00

25 lines
1.1 KiB
TypeScript

// npx ts-node xlsx-template.ts
import * as readline from "node:readline/promises" // This uses the promise-based APIs
import { stdin as input, stdout as output } from "node:process"
import { xlsxTemplateX } from "../libs/xlsx-template-lib"
import { templateOption } from "../libs/report-template"
import fs from "fs"
;(async () => {
const rl = readline.createInterface({ input, output })
const e = await rl.question("Output extension(xlsx,pdf,ods,png,jpeg): ")
const ext = e ? e : "xlsx"
const dpath = await rl.question("JSON data path(./xlsx.json): ")
const datapath = dpath ? dpath : "./xlsx.json"
const data_raw = fs.readFileSync(datapath)
const tdata: templateOption = JSON.parse(data_raw.toString())
const bpath = await rl.question("template path(../templates/xlsx): ")
const basepath = bpath ? bpath : "../templates/xlsx"
// const template = await fs.promises.readFile(`${basepath}/${tdata.template}.xlsx`)
let buffer = await xlsxTemplateX(
`${basepath}/${tdata.template}.xlsx`,
tdata,
ext
)
fs.writeFileSync(tdata.reportName + "." + ext, buffer)
rl.close()
})()