GithubHelp home page GithubHelp logo

excel-exporter's Introduction

excel-exporter

=========== Exports Java objects to Microsoft Excel Reports.

Usage overview

Offers 2 ways for exporting Java objects to Microsoft Excel Reports:

  • By annotating java objects using the annotation @ExcelColumn,
  • By creating and populating an ExcelReport object.

Annotation example

Java class

@ExcelReport(reportName = "modeReport.xls")
public class Model {

	private String name;

	private int age;

	private double money;

	private String discard;

	@ExcelColumn(label = "Name")
	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	@ExcelColumn(label = "Age")
	public int getAge() {
		return age;
	}

	public void setAge(final int age) {
		this.age = age;
	}

	@ExcelColumn(label = "Money")
	public double getMoney() {
		return money;
	}

	public void setMoney(final double money) {
		this.money = money;
	}

	@ExcelColumn(ignore = true)
	public String getDiscard() {
		return discard;
	}

	public void setDiscard(final String discard) {
		this.discard = discard;
	}

}

Exporting report

	@Resource(name = "idAnnotatedExcelExporter")
	private IAnnotatedExcelExporter anService;
	
	public void testAnnotatedExport() throws ExcelReporterException, IOException {
		final byte[] bytes = anService.listToExcel(getObjectsList());
		Utils.saveWorksheet(bytes, "testAnnotatedExport.xls");	
	}

ExcelReport example

	@Resource(name = "idExcelExporter")
	private IExcelExporter service;
	
	public void testExcelReport() throws ExcelReporterException, IOException {

		final ExcelReport report = getExcelReport();
		final byte[] bytes = service.reportToExcel(report);

		Utils.saveWorksheet(bytes, "testGenericExport.xls");

		assert bytes != null;

	}	

	private ExcelReport getExcelReport() {
		final ExcelReport report = new ExcelReport();
		final int nrows = 100;

		report.addHeader("Column 1");
		report.addHeader("Column 2");
		report.addHeader("Column 3");
		report.addHeader("Column 4");
		report.addHeader("Column 5");

		for (int i = 1; i <= nrows; i++) {

			final List<Object> row = new ArrayList<Object>();

			final Double col_1 = Double.valueOf(i * 2.5);
			final Long col_2 = Long.valueOf(i * 1);
			final String col_3 = "Column " + i;
			final Date col_4 = new Date();
			final Float col_5 = Float.valueOf((float) (i * 1.02));

			row.add(col_1);
			row.add(col_2);
			row.add(col_3);
			row.add(col_4);
			row.add(col_5);

			report.addRow(row);

		}

		return report;

	}

Maven Dependency - Service

<dependency>
 <groupId>com.github.vsspt</groupId>
 <artifactId>excel-exporter</artifactId>
 <version>1.0.0</version>
</dependency>

What's new

Version 1.0.0

  • Initial deployment

excel-exporter's People

Contributors

vsspt avatar prathmesh01 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.