Skip to content

simter/simter-jxls-ext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simter Jxls Extensions. Includes:

  • Common Functions

    • Format number: fn.format(1123456789.456, '#,###.00') > 1,123,456,789.56
    • Round number: fn.round(45.678, 2) > 45.68
    • Convert string to int: fn.toInt('123') > 123
    • Concat multipul strings: fn.concat('ab', 'c', ...) > 'abc'
    • Format java8 date/time: fn.format(LocalDateTime.now(), 'yyyy-MM-dd HH:mm:ss') > 2017-01-01 12:30:50
  • EachMergeCommand: jx:each-merge, for auto merge cells

See the usage code bellow.

Installation

<dependency>
  <groupId>tech.simter</groupId>
  <artifactId>simter-jxls-ext</artifactId>
  <version>1.0.0</version>
</dependency>

Requirement

Usage

Common Functions

Context context = new Context();

// inject common-functions
context.putVar("fn", CommonFunctions.getSingleton());

// other data
context.putVar("num", new BigDecimal("123.456"));
context.putVar("datetime", LocalDateTime.now());
context.putVar("date", LocalDate.now());
context.putVar("time", LocalTime.now());
context.putVar("str", "123");

// render template
InputStream template = ...;
OutputStream output = ...;
JxlsHelper.getInstance().processTemplate(template, output, context);

Check the unit test code from CommonFunctionsTest.java. The template and render result show bellow:

common-functions.png

EachMergeCommand - Auto merge cells

// global add custom each-merge command to XlsCommentAreaBuilder
XlsCommentAreaBuilder.addCommandMapping(EachMergeCommand.COMMAND_NAME, EachMergeCommand.class);

// generate a main-sub structure data
Context context = new Context();
context.putVar("rows", generateRowsData());

// render template
InputStream template = ...;
OutputStream output = ...;
JxlsHelper.getInstance().processTemplate(template, output, context);

The generateRowsData() method generates the bellow structure data:

[
  {
    sn: 1, 
    name: 'row1',
    subs: [
      {sn: '1-1', name: 'row1sub1'},
      ...
    ]
  },
  ...
]

Check the unit test code from EachMergeCommandTest.java. The template and render result show bellow:

each-merge.png

Build

mvn clean package

Deploy

First take a look at simter-parent deploy config.

Deploy to LAN Nexus Repository

mvn clean deploy -P lan

Deploy to Sonatype Repository

mvn clean deploy -P sonatype

After deployed, login into https://oss.sonatype.org. Through Staging Repositories, search this package, then close and release it. After couple hours, it will be synced to Maven Central Repository.

Deploy to Bintray Repository

mvn clean deploy -P bintray

Will deploy to https://api.bintray.com/maven/simter/maven/tech.simter:simter-jxls-ext/;publish=1. So first create a package https://bintray.com/simter/maven/tech.simter:simter-jxls-ext on Bintray. After deployed, check it from https://jcenter.bintray.com/tech/simter/simter-jxls-ext.