{"size": 4970, "ext": "js", "max_stars_repo_path": "bundle/base/apps/demo/server/services/samples/javascript/export-excel.js", "max_stars_repo_name": "netuno-org/platform", "max_stars_repo_stars_event_min_datetime": "2021-08-06T20:40:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T11:05:49.000Z", "max_issues_repo_path": "bundle/base/apps/demo/server/services/samples/javascript/export-excel.js", "max_issues_repo_name": "netuno-org/platform", "max_issues_repo_issues_event_min_datetime": "2022-03-09T23:01:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T23:01:29.000Z", "max_forks_repo_path": "bundle/base/apps/demo/server/services/samples/javascript/export-excel.js", "max_forks_repo_name": "netuno-org/platform", "max_forks_repo_forks_event_min_datetime": "2022-01-30T16:49:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T17:42:10.000Z"}
{"max_stars_count": 19, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 28.0790960452, "max_line_length": 74, "alphanum_fraction": 0.5390342052}

/**
 *
 *  EN: Export EXCEL
 *  EN: Generates an Excel file in real time showing how to inject data,
 *  EN: use formulas, and apply graphic styles.
 *
 *  PT: Export EXCEL
 *  PT: Gera um ficheiro Excel em tempo real mostrando como injetar dados,
 *  PT: utilizar fórmulas e aplicar estilos gráficos.
 *
 */

var excel = _xls.create()

var fontTitle = excel.workbook.createFont()
fontTitle.setBold(true)
fontTitle.setFontHeightInPoints(14)
fontTitle.setColor(_xls.color("yellow"))

var fontTotal = excel.workbook.createFont()
fontTotal.setBold(true)
fontTotal.setFontHeightInPoints(12)
fontTotal.setColor(_xls.color("grey-50-percent"))

var styleHeader = excel.workbook.createCellStyle()

styleHeader.setFillPattern(_xls.fillPattern("solid-foreground"))
styleHeader.setFillBackgroundColor(_xls.color("black"))
styleHeader.setAlignment(_xls.horizontalAlignment("center"))

styleHeader.setFont(fontTitle);

var styleData = excel.workbook.createCellStyle()
styleData.setBorderBottom(_xls.borderStyle("thin"))
styleData.setBorderTop(_xls.borderStyle("thin"))
styleData.setBorderLeft(_xls.borderStyle("thin"))
styleData.setBorderRight(_xls.borderStyle("thin"))

var styleTotal = excel.workbook.createCellStyle()

styleTotal.setBorderBottom(_xls.borderStyle("thin"))
styleTotal.setBorderTop(_xls.borderStyle("thin"))
styleTotal.setBorderLeft(_xls.borderStyle("thin"))
styleTotal.setBorderRight(_xls.borderStyle("thin"))

styleTotal.setTopBorderColor(_xls.color("red"))
styleTotal.setBottomBorderColor(_xls.color("blue"))
styleTotal.setLeftBorderColor(_xls.color("pink"))
styleTotal.setRightBorderColor(_xls.color("orange"))

styleTotal.setAlignment(_xls.horizontalAlignment("center"))

styleTotal.setFont(fontTotal);

excel.insertPicture(
    _storage.filesystem("server", "samples/export-excel", "logo.png"),
    1, 1
).resize(2.3)

excel.sheet.addMergedRegion(_xls.cellRangeAddress(1, 3, 1, 3))

var dataTitle = _val.init()
    .add(
        _val.init()
            .set("value", "Name")
            .set("style", styleHeader)
    ).add(
        _val.init()
            .set("value", "Age")
            .set("style", styleHeader)
    ).add(
        _val.init()
            .set("value", "Weight")
            .set("style", styleHeader)
    )

var data = _val.init()
    .add(
        _val.init()
            .add(
                _val.init()
                    .set("value", "Briana")
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 24)
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 73.2)
                    .set("style", styleData)
            )
    ).add(
        _val.init()
            .add(
                _val.init()
                    .set("value", "Kelly")
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 27)
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 79.5)
                    .set("style", styleData)
            )
    ).add(
        _val.init()
            .add(
                _val.init()
                    .set("value", "Peter")
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 28)
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 84.9)
                    .set("style", styleData)
            )
    ).add(
        _val.init()
            .add(
                _val.init()
                    .set("value", "Simon")
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 21)
                    .set("style", styleData)
            )
            .add(
                _val.init()
                    .set("value", 68.3)
                    .set("style", styleData)
            )
    )

var dataResult = _val.init()
    .add(
        _val.init()
            .set("value", "Result")
            .set("style", styleTotal)
    ).add(
        _val.init()
            .set("formula", "ROUND(SUM(C8:C11)/COUNT(C8:C11), 2)")
            .set("style", styleTotal)
    ).add(
        _val.init()
            .set("formula", "ROUND(SUM(D8:D11)/COUNT(D8:D11), 2)")
            .set("style", styleTotal)
    )

var endPosition = excel.addDataTable(6, 1, dataTitle)

endPosition = excel.addDataTable(endPosition.row, 1, data)

endPosition = excel.addDataTable(endPosition.row, 1, dataResult)

endPosition = excel.addDataTable(6, endPosition.col + 2, dataTitle, true)

endPosition = excel.addDataTable(6, endPosition.col, data, true)

endPosition = excel.addDataTable(6, endPosition.col, dataResult, true)

excel.output("test.xls")
