Support TS, swagger,Template(xls,docx),PDF convert
This commit is contained in:
parent
b221deb1cf
commit
8d7654423a
84 changed files with 3604 additions and 1 deletions
21
test-run/docx-template.ts
Normal file
21
test-run/docx-template.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
// npx ts-node docx-templates.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 { docxTemplateX} from '../src/libs/docx-templates-lib';
|
||||
import {templateData} from '../src/libs/report-template'
|
||||
import fs from 'fs';
|
||||
(async ()=>{
|
||||
const rl = readline.createInterface({ input, output });
|
||||
const e = await rl.question('Output extension(docx,pdf,odt): ');
|
||||
const ext =e?e:"docx"
|
||||
const dpath = await rl.question('JSON data path(./docx.json): ');
|
||||
const datapath = dpath?dpath:"./docx.json"
|
||||
const data_raw = fs.readFileSync(datapath);
|
||||
const tdata:templateData = JSON.parse(data_raw.toString());
|
||||
const bpath = await rl.question('Base path of templates-docx(..): ');
|
||||
const basepath = bpath?bpath:".."
|
||||
let buffer = await docxTemplateX(basepath,tdata,ext)
|
||||
fs.writeFileSync(tdata.reportName+"."+ext, buffer);
|
||||
rl.close();
|
||||
})()
|
||||
28
test-run/docx.json
Normal file
28
test-run/docx.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
|
||||
"template": "hello",
|
||||
"reportName": "report-docx",
|
||||
"data": {
|
||||
"docNo": "๑๒๓๔๕",
|
||||
"me": "กระผม",
|
||||
"prefix": "นาย",
|
||||
"name": "สรวิชญ์",
|
||||
"surname": "พลสิทธิ์",
|
||||
"position": "Chief Technology Officer",
|
||||
"org": {
|
||||
"type": "บริษัท",
|
||||
"name": "เฟรปเป้ที",
|
||||
"url": "https://frappet.com"
|
||||
},
|
||||
"employees": [
|
||||
{
|
||||
"name": "ภาวิชญ์",
|
||||
"surname": "พลสิทธิ์"
|
||||
},
|
||||
{
|
||||
"name": "วิชญาภา",
|
||||
"surname": "พลสิทธิ์"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
BIN
test-run/report-docx.pdf
Normal file
BIN
test-run/report-docx.pdf
Normal file
Binary file not shown.
BIN
test-run/report-xlsx.pdf
Normal file
BIN
test-run/report-xlsx.pdf
Normal file
Binary file not shown.
BIN
test-run/report.docx
Normal file
BIN
test-run/report.docx
Normal file
Binary file not shown.
BIN
test-run/report.odt
Normal file
BIN
test-run/report.odt
Normal file
Binary file not shown.
BIN
test-run/report.pdf
Normal file
BIN
test-run/report.pdf
Normal file
Binary file not shown.
21
test-run/xlsx-template.ts
Normal file
21
test-run/xlsx-template.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
// 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 '../src/libs/xlsx-template-lib'
|
||||
import {templateData} from '../src/libs/report-template'
|
||||
import fs from 'fs';
|
||||
(async ()=>{
|
||||
const rl = readline.createInterface({ input, output });
|
||||
const e = await rl.question('Output extension(xlsx,pdf,ods): ');
|
||||
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:templateData = JSON.parse(data_raw.toString());
|
||||
const bpath = await rl.question('Base path of templates-docx(..): ');
|
||||
const basepath = bpath?bpath:".."
|
||||
let buffer = await xlsxTemplateX(basepath,tdata,ext)
|
||||
fs.writeFileSync(tdata.reportName+"."+ext, buffer);
|
||||
rl.close();
|
||||
})()
|
||||
44
test-run/xlsx.json
Normal file
44
test-run/xlsx.json
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"template": "hello",
|
||||
"reportName": "report-xlsx",
|
||||
"data": {
|
||||
"docNo": "๑๒๓๔๕",
|
||||
"me": "กระผม",
|
||||
"prefix": "นาย",
|
||||
"name": "สรวิชญ์",
|
||||
"surname": "พลสิทธิ์",
|
||||
"position": "Chief Technology Officer",
|
||||
"org": {
|
||||
"type": "บริษัท",
|
||||
"name": "เฟรปเป้ที",
|
||||
"url": "https://frappet.com"
|
||||
},
|
||||
"employees": [
|
||||
{
|
||||
"id":1,
|
||||
"name": "ภาวิชญ์",
|
||||
"surname": "พลสิทธิ์",
|
||||
"score":80
|
||||
},
|
||||
{
|
||||
"id":2,
|
||||
"name": "วิชญาภา",
|
||||
"surname": "พลสิทธิ์",
|
||||
"score":50
|
||||
},
|
||||
{
|
||||
"id":3,
|
||||
"name": "ฐิตาภา",
|
||||
"surname": "พลสิทธิ์",
|
||||
"score":90
|
||||
},
|
||||
{
|
||||
"id":4,
|
||||
"name": "สรวิชญ์ พลสิทธิ์",
|
||||
"surname": "พลสิทธิ์",
|
||||
"score":99
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue