excel2canvas

Return to index link to github

Overview

Excel2Canvas is a library to display an Excel file on the web browser.

Its source codes consists of two parts.

  • Java. It is used to convert Excel file to JSON.
  • JavaScript. It is used to draw Excel view on the web browser.

Usage

JavaDoc

At first, read an excel file and convert it to JSON string.

    ExcelToCanvasBuilder builder = new ExcelToCanvasBuilder();
    builder.setIncludeComment(true);//If need display comments.
    builder.setIncludeChart(true);//If need display charts.(Flotr2 is required.)
    builder.setIncludePicture(true);//If need display picture.
    String json = builder.build(new File("Book1.xlsx"), "Sheet1").toJson();

Next, embed JSON string to HTML, and apply jQuery plugin method to a div element that holding a canvas element.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    
    <link rel="stylesheet" type="text/css" media="screen,print" href="jquery.excel2canvas.css" />
    <script type="text/javascript" language="javascript"  src="flotr2.js"></script>
    <script type="text/javascript" language="javascript"  src="jquery.excel2canvas.min.js"></script>
    <script type="text/javascript" language="javascript"  src="jquery.excel2chart.flotr2.min.js"></script>
    
    <script>
        $(function() {
        var data = ${excel.raw()};//Get the JSON string.(Template engine syntax.)
        $("#canvasHolder").excelToCanvas(data).css("width", $("#canvas").width());
    });
    </script>
    
    ...
    
    <div id="canvasHolder">
        <canvas id="canvas"></canvas>
    </div>

You can see more detail on SlideShare.(Japanese only)


Sample

ExcelReport is an application that uses this library.

It allows you to display Excel form in the browser.

Followings are some of its samples.


Latest release

Download - 1.2.0

Maven

    <repositories>
        <repository>
            <id>jp.co.flect</id>
            <name>FLECT maven repository</name>
            <url>http://flect.github.io/maven-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>jp.co.flect</groupId>
            <artifactId>excel2canvas</artifactId>
            <version>1.2.0</version>
        </dependency>
    </dependencies>

License

MIT