mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
- Fix uploadImport/importUpload variable name mismatch in index.js and importRoutes.js - Add missing toCamelCase imports in categories.js and portfolio.js - Apply prettier formatting across all backend files
45 lines
887 B
JavaScript
45 lines
887 B
JavaScript
/**
|
|
* Spreadsheet Service — wraps xlsx/SheetJS for import parsing.
|
|
*/
|
|
|
|
let _XLSX = null;
|
|
|
|
function getXLSX() {
|
|
if (!_XLSX) {
|
|
_XLSX = require('xlsx');
|
|
}
|
|
return _XLSX;
|
|
}
|
|
|
|
function readFile(filepath) {
|
|
const XLSX = getXLSX();
|
|
const workbook = XLSX.readFile(filepath);
|
|
return {
|
|
sheetNames: workbook.SheetNames,
|
|
sheets: workbook.Sheets,
|
|
workbook,
|
|
};
|
|
}
|
|
|
|
function readBuffer(buf) {
|
|
const XLSX = getXLSX();
|
|
const workbook = XLSX.read(buf, { type: 'array' });
|
|
return {
|
|
sheetNames: workbook.SheetNames,
|
|
sheets: workbook.Sheets,
|
|
workbook,
|
|
};
|
|
}
|
|
|
|
function sheetToJson(sheet, options) {
|
|
const XLSX = getXLSX();
|
|
return XLSX.utils.sheet_to_json(sheet, options);
|
|
}
|
|
|
|
function parseExcelDate(dateStr) {
|
|
const XLSX = getXLSX();
|
|
return XLSX.SSF.parse_date_code(dateStr);
|
|
}
|
|
|
|
module.exports = { readFile, readBuffer, sheetToJson, parseExcelDate };
|