Git Product home page Git Product logo

lib-html-exporter's Introduction

HTML Export library

An Enonic XP library to export simple HTML with CSS to Excel and PDF.

The library is built on top of https://github.com/alanhay/html-exporter with some modifications.

Usage

To install this library you need to update your build.gradle file.

Gradle build script

repositories {
    maven {
      url 'https://dl.bintray.com/openxp/public'
    }
}

dependencies {
     include 'openxp.lib:htmlexporter:1.0.0'
}

Examples and feature application

An example application is created to see how html can be converted to Excel and PDF. download url: https://github.com/rbrastad/lib-html-exporter/raw/master/html-exporter-examples/build/libs/html_export_examples-1.0.0.jar

Install and access the application on URL: SERVER_HOSTNAME/app/openxp.app.html.exporter.examples

The application is built for version +6.12.0

Example: HTML to Excel and PDF controller example

var htmlExporter = require('/lib/openxp/html-exporter');
var ioLib = require("/lib/xp/io");

exports.get = function(req, type) {
    var fileSource = null;

    if (type == 'pdf') {
		fileSource = htmlToPDF();
    } else {
        fileSource = htmlToExcel();
    }
    
    // Stream the file content to the client
    return {
        body: htmlExporter.getStream(fileSource),
        headers: {
            'Content-Disposition': 'attachment; filename="' + fileSource.name + '"'
        }
    };
};

function htmlToExcel() {
    var fileSource = htmlExporter.exportToExcel(getHtml());
    fileSource.name = 'htmlExporterTest.xlsx';

    return fileSource;
}

function htmlToPDF() {
    var fileSource = htmlExporter.exportToPdf(getHtml());
    fileSource.name = 'htmlExporterTest.pdf';

    return fileSource;
}

function getHtml() {
    return ioLib.readText(ioLib.getResource(resolve('html-exporter-test.html')).getStream());
}

Example HTML used can be found here: https://github.com/rbrastad/lib-html-exporter/blob/master/html-exporter-examples/src/main/resources/controller/htmlexport/html-exporter-test.html

Formula in Excel

The Excel exporters allow for producing spreadsheets with automatic formula insertion via the use of various HTML5 compliant data-* attributes being applied to table cells. The sample spreadsheets linked to above demonstrate this functionality.

Example:

<!-- This cell will, via the data-group attribute,  be added to two ranges, each of which will be the inputs to formulas -->
<td data-group="store_Dumfries_2_value, region_1_1_pg_5_value" class="numeric">
    486
</td>

...

<!--
    This raw value of this cell will, via the data-group-output attribute, be replaced with a SUM function taking as input all cells added to the specified range.
    The cell is then itself added to another range which will be used by a further function.
-->
<td class="subTotal numeric" data-group-output="region_1_1_pg_6_count" data-group="area_1_pg_6_cou

Screenshots

HTML Exporter Examples APP

Excel

PDF

lib-html-exporter's People

Contributors

rbrastad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.