Apache POI, being a complete solution, is quite heavyweight. This library provide only the minimal amount of functionality to write xlsx files.
basicxlsx is licensed under the Apache License Version 2.0.
maven:
<dependency>
<groupId>ch.digitalfondue.basicxlsx</groupId>
<artifactId>basicxlsx</artifactId>
<version>0.7.1</version>
</dependency>
gradle:
compile 'ch.digitalfondue.basicxlsx:basicxlsx:0.7.1'
Available at javadoc.io.
The api is minimalistic, basically you only need to choose Workbook type (streaming or not), define your styles, define the data and write the workbook to an OutputStream.
If you use it as a module, remember to add requires ch.digitalfondue.basicxlsx;
in your module-info.
import ch.digitalfondue.basicxlsx.*;
import java.io.FileOutputStream;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
Workbook w = new Workbook();
Sheet s = w.sheet("test"); //create a new sheet named test
s.setValueAt("Hello World", /*row*/ 0, /*column*/ 0); //put in "A1" the value "Hello World"
//write the workbook to a file
try (FileOutputStream fos = new FileOutputStream("test.xlsx")) {
w.write(fos);
}
}
}
import ch.digitalfondue.basicxlsx.*;
import java.io.FileOutputStream;
import java.io.IOException;
public class ExampleWithStyle {
public static void main(String[] args) throws IOException {
Workbook w = new Workbook();
// you must define the styles before using them
Style redBGBold = w.defineStyle().bgColor(Style.Color.RED).font().bold(true).build();
//
Sheet s = w.sheet("test"); //create a new sheet named test
s.setValueAt("Hello World", /*row*/ 0, /*column*/ 0).withStyle(redBGBold); //put in "A1" the value "Hello World", set the style to the cell
//write the workbook to a file
try (FileOutputStream fos = new FileOutputStream("test.xlsx")) {
w.write(fos);
}
}
}
See https://github.com/digitalfondue/basicxlsx/blob/master/src/test/java/ch/digitalfondue/basicxlsx/WorkbookTest.java for a more complete example with style, formatting and other data types.
import ch.digitalfondue.basicxlsx.Cell;
import ch.digitalfondue.basicxlsx.StreamingWorkbook;
import ch.digitalfondue.basicxlsx.StreamingWorkbook.Row;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.stream.Stream;
public class ExampleStreaming {
public static void main(String[] args) throws IOException {
try (FileOutputStream fos = new FileOutputStream("test.xlsx");
StreamingWorkbook w = new StreamingWorkbook(fos)) { //<- create a StreamingWorkbook: it require the outputstream
Cell[] row1 = new Cell[] {Cell.cell("Hello World")};
Stream<Row> rows = Stream.of(StreamingWorkbook.row(row1));
w.withSheet("test", rows); //write a new sheet named "test" with the stream of rows
}
}
}
import ch.digitalfondue.basicxlsx.Cell;
import ch.digitalfondue.basicxlsx.StreamingWorkbook;
import ch.digitalfondue.basicxlsx.StreamingWorkbook.Row;
import ch.digitalfondue.basicxlsx.Style;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.stream.Stream;
public class ExampleStreamingWithStyle {
public static void main(String[] args) throws IOException {
try (FileOutputStream fos = new FileOutputStream("test.xlsx");
StreamingWorkbook w = new StreamingWorkbook(fos)) { //<- create a StreamingWorkbook: it require the outputstream
// you must define the styles before
Style redBGBold = w.defineStyle().bgColor(Style.Color.RED).font().bold(true).build();
//
Cell[] row1 = new Cell[] {Cell.cell("Hello World").withStyle(redBGBold)};
Stream<Row> rows = Stream.of(StreamingWorkbook.row(row1));
w.withSheet("test", rows); //write a new sheet named "test" with the stream of rows
}
}
}
See https://github.com/digitalfondue/basicxlsx/blob/master/src/test/java/ch/digitalfondue/basicxlsx/StreamingWorkbookTest.java for a more complete example with style, formatting and other data types.
- add more test
- write javadoc
- merged cell
- charts
- conditional formatting
- ... ?
- styling
- complete missing alignment
- indent https://xlsxwriter.readthedocs.io/format.html#format-set-indent (some gotcha are present it seems...)
- see for other missing https://xlsxwriter.readthedocs.io/format.html
- http://officeopenxml.com/anatomyofOOXML-xlsx.php
- https://social.technet.microsoft.com/wiki/contents/articles/19601.powershell-generate-real-excel-xlsx-files-without-excel.aspx
- https://github.com/mk-j/PHP_XLSXWriter
- https://github.com/jmcnamara/XlsxWriter
mvn com.mycila:license-maven-plugin:format
mvn versions:display-dependency-updates
mvn versions:display-plugin-updates