VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-acomp/demo/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-acomp/demo/excel_module.js
var excel_module = {};
window.excel_module = excel_module;
excel_module.distanceDefine = 5;
excel_module.load = function (buffer, opt) {
    var wb = new ExcelJS.Workbook();
    return new Promise(function (resolve, reject) {
        wb.xlsx.load(buffer).then(workbook => {
            var final = {};
            final.sheets = [];
            workbook.eachSheet((sheet, id) => {
                final.sheets.push(excel_module.extractSheet(sheet, id, opt));
            });
            resolve(final);
        })
    })
}

excel_module.explicitCellValue = function (value, opt) {
    var valueOnly = true;
    if (opt && opt.valueOnly === false) {
        valueOnly = false;
    }

    if (typeof value === 'object') {
        if ('result' in value) value = value.result;
    }
    return value;
};

excel_module.extractSheet = function (sheet, id, opt) {

    var final = {};
    final.name = sheet.name;
    final.data = [];
    sheet.eachRow((row, rowIndex) => {
        row.values.forEach(function (value, index) {
            final.data.push({
                row: rowIndex,
                col: index,
                value: excel_module.explicitCellValue(value)
            });
        });
    })
    return final;
}

excel_module.writerWorkbook = function (excelData, fileName) {
    console.log(excelData, fileName)
    var wb = new ExcelJS.Workbook();
    var sheet;
    for (var i = 0; i < excelData.sheets.length; i++) {
        excel_module.writerSheet(wb, excelData.sheets[i]);
    }
    wb.xlsx.writeBuffer().then(function (data) {
        var blob = new Blob([data], {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        });
        excel_module.saveData(blob, fileName);
    });
}

excel_module.writerSheet = function (workbook, sheetData) {

    var sheet = workbook.addWorksheet(sheetData.name);
    sheet.cellWidthData = sheet.cellWidthData || [];
    sheet.cellWidthData.forEach(function (it) {
        if (it && (typeof it.width === "string") && it.width.endsWith('px')) {
            it.defineWidth = true;
            it.value = parseFloat(it.width.replace('px', '')) || 0;
        }
    })
    for (var i = 0; i < sheetData.data.length; i++) {
        excel_module.cell(sheet, sheetData.data[i]);
    }
    for (var i = 0; i < sheet.cellWidthData.length; i++) {
        if (sheet.cellWidthData[i] !== undefined)
            sheet.getColumn(i + 1).width = sheet.cellWidthData[i].value / 5;
    }
}

excel_module.saveData = function (blob, fileName) {
    var link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = fileName;
    link.click();
};

excel_module.cell = function (sheet, cellData) {
    var cell = sheet.getCellByRowCol(cellData.row, cellData.col);
    var row, textRows;
    var style;
    var temp;

    var colSpan = 1;
    var rowSpan = 1;
    var boolMerge = false;
    if (cellData.colSpan !== undefined) {
        colSpan = cellData.colSpan;
        boolMerge = true;
    }
    if (cellData.rowSpan !== undefined) {
        rowSpan = cellData.rowSpan;
        boolMerge = true;
    }
    if (cell.isMerged === false && boolMerge === true)
        sheet.mergeCells(cellData.row + 1, cellData.col + 1, cellData.row + rowSpan, cellData.col + colSpan);

    cell.alignment = {};

    if (cellData.alignment) {
        Object.assign(cell.alignment, cellData.alignment);
    }

    if (cellData.horizontal !== undefined) {
        cell.alignment.horizontal = cellData.horizontal;
    }

    if (cellData.vertical !== undefined) {
        cell.alignment.vertical = cellData.vertical;
    }

    if (cellData.wraptext !== undefined || cellData.wrapText !== undefined) {
        cell.alignment.wrapText = cellData.wraptext || cellData.wrapText;
    }

    if (cell.alignment.wrapText && typeof cellData.value === "string") {
        row = sheet.getRow(cellData.row + 1); //todo: default for 11px
        textRows = cellData.value.split('\n');
        if (textRows.length > 1) {
            row.height = Math.max(row.height || 20, 20 * textRows.length);
        }
    }

    cell.font = {};
    if (sheet.cellWidthData[cellData.col] === undefined) {
        sheet.cellWidthData[cellData.col] = {};
        sheet.cellWidthData[cellData.col].value = 0;
    }

    if (cellData.width !== undefined) {
        sheet.cellWidthData[cellData.col].value = Number(cellData.width.replace("px", ""));
        sheet.cellWidthData[cellData.col].defineWidth = true;
    }

    if (cellData.numberformat !== undefined)
        cell.numFmt = cellData.numberformat;
    var cellTextWidth = 0;
    var textCaculator = "";

    if (cellData.numberformat !== undefined && cellData.numberformat !== "") {
        temp = cellData.numberformat.toString();
        temp = temp.slice(temp.lastIndexOf('.'));
        textCaculator = Number.parseFloat(cellData.value).toFixed(temp.length);
    }
    else
        textCaculator = cellData.value;

    if (cellData.font !== undefined) {
        cellTextWidth = absol.text.measureText(textCaculator, cellData.font).width + excel_module.distanceDefine;
    }
    else
        cellTextWidth = absol.text.measureText(textCaculator, '11px Calibri').width + excel_module.distanceDefine;

    if ((!cellData.colSpan || cellData.colSpan < 2) && sheet.cellWidthData[cellData.col].defineWidth !== true && sheet.cellWidthData[cellData.col].value < cellTextWidth) {
        console.log('assign col', cellData.col, sheet.cellWidthData[cellData.col].value, cellTextWidth)
        sheet.cellWidthData[cellData.col].value = cellTextWidth;
    }

    if (cellData.font !== undefined) {
        style = excel_module.extractFont(".testFontCss{font:" + cellData.font + "}", ".testFontCss");
        if (style.getPropertyValue("fontFamily") != "")
            cell.font.name = style.getPropertyValue("fontFamily");
        if (style.getPropertyValue("fontSize") != "")
            cell.font.size = Number(style.getPropertyValue("fontSize").replace("px", ""));
    }

    if (cellData.border !== undefined) {
        style = excel_module.extractFont(".testFontCss{border:" + cellData.border + "}", ".testFontCss");
        cell.border = {
            top: {
                style: style.borderTopWidth,
                color: {
                    argb: excel_module.argbToRGB(style.borderTopColor)
                }
            },
            left: {
                style: style.borderLeftWidth,
                color: {
                    argb: excel_module.argbToRGB(style.borderLeftColor)
                }
            },
            bottom: {
                style: style.borderLeftWidth,
                color: {
                    argb: excel_module.argbToRGB(style.borderBottomColor)
                }
            },
            right: {
                style: style.borderLeftWidth,
                color: {
                    argb: excel_module.argbToRGB(style.borderRightColor)
                }
            }
        };
    }
    if (cellData.bold !== undefined)
        cell.font.bold = cellData.bold;

    if (cellData.italic !== undefined)
        cell.font.italic = cellData.italic;

    if (cellData.underline !== undefined)
        cell.font.underline = cellData.underline;

    if (cellData.textcolor !== undefined)
        cell.font.color = {
            argb: cellData.textcolor
        };

    if (cellData.isFormula !== undefined) {
        cell.value = {
            formula: cellData.isFormula,
            result: cellData.value
        };
    }
    else
        cell.value = cellData.value;

    if (cellData.backgroundcolor !== undefined)
        cell.fill = {
            type: 'pattern',
            pattern: 'solid',
            fgColor: {
                argb: cellData.backgroundcolor
            },
            bgColor: 64
        };


}

excel_module.extractFont = function (css, selector) {
    var style = document.createElement('style');
    style.appendChild(document.createTextNode(css));
    document.body.appendChild(style);
    var sheet = style.sheet;
    style.remove();
    var rule = Array
        .from(sheet.cssRules)
        .find(cssRule => cssRule.selectorText === selector);

    if (rule) {
        return rule.style;
    }
    return undefined;
}

excel_module.argbToRGB = function (orig) {
    var a, isPercent,
        rgb = orig.replace(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+),?([^,\s)]+)?/i),
        alpha = (rgb && rgb[4] || "").trim(),
        hex = rgb ?
            (rgb[1] | 1 << 8).toString(16).slice(1) +
            (rgb[2] | 1 << 8).toString(16).slice(1) +
            (rgb[3] | 1 << 8).toString(16).slice(1) : orig;

    if (alpha !== "") {
        a = alpha;
    }
    else {
        a = 1;
    }
    // multiply before convert to HEX
    a = ((a * 255) | 1 << 8).toString(16).slice(1)
    hex = hex + a;

    return hex.toLocaleUpperCase();
};

(function (module) {
    var CAPITAL_A = 65;

    function excelCoords(row, col) {
        var colStr = '';

        while (col > 0) {
            colStr = toChar((col - 1) % 26) + colStr;
            col = Math.floor((col - 1) / 26);
        }

        return colStr + row;
    }

    function toChar(n) {
        return String.fromCharCode(CAPITAL_A + n);
    }

    // The inverse is also quite simple:

    function cartesianCoords(excelCoords) {
        var row = parseInt(excelCoords.replace(/^[A-Z]+/, ''));
        var colChars = excelCoords.replace(/\d+$/, '').split('').reverse();
        var col = 0;
        var multiplier = 1;

        while (colChars.length) {
            col += toBase26Ish(colChars.shift()) * multiplier;
            multiplier *= 26;
        }

        return [row, col];
    }

    function toBase26Ish(c) {
        return c.charCodeAt(0) - CAPITAL_A + 1;
    }

    module.cartesianCoords = cartesianCoords;
    module.excelCoords = excelCoords;
})(excel_module);
/*

hr.report_employees.exportData = function(host){console.log()}
hr.report_employees.exportData = function(host){
    console.log(host)
    var x = contentModule.getDateTimeView(new Date());
    var startWorker = function(result, fileName = "report"+x+".xlsx") {
        var w;
        if(typeof(Worker) !== "undefined") {
            if(typeof(w) == "undefined") {
                w = new Worker(window.domain + "js/exceljs.js");
                w.postMessage(result);
            }
            w.onmessage = function(event) {
                var data = event.data;
                if(data.name == "end")
                {
                    var link = document.createElement('a');
                    link.href = window.URL.createObjectURL(data.data);
                    link.download = fileName;
                    link.click();
                }
            }
        } else {
            console.log("Sorry, your browser does not support Web Workers...");
        }
    }
    startWorker(host.excelData);
}*/

VaKeR 2022