All Projects → tobyweston → simple-excel

tobyweston / simple-excel

Licence: Apache-2.0 License
Generate excel sheets in Java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to simple-excel

Excel Boot
Easy-POI是一款Excel导入导出解决方案组成的轻量级开源组件。
Stars: ✭ 347 (+308.24%)
Mutual labels:  excel, poi
Hy.common.report
报表、Excel操作类库。Java转Excel、Excel转Java
Stars: ✭ 124 (+45.88%)
Mutual labels:  excel, poi
Easyexcel
快速、简单避免OOM的java处理Excel工具
Stars: ✭ 22,133 (+25938.82%)
Mutual labels:  excel, poi
Poiji
🍬 A tiny library converting excel rows to a list of Java objects based on Apache POI
Stars: ✭ 255 (+200%)
Mutual labels:  excel, poi
java-8-matchers
Hamcrest Matchers for Java 8 features
Stars: ✭ 23 (-72.94%)
Mutual labels:  hamcrest, hamcrest-matchers
Excel4j
✨ Excel operation component based on poi & CSV ✨
Stars: ✭ 305 (+258.82%)
Mutual labels:  excel, poi
Poi Android
📈 Apache POI for Android
Stars: ✭ 77 (-9.41%)
Mutual labels:  excel, poi
Myexcel
MyExcel, a new way to operate excel!
Stars: ✭ 1,198 (+1309.41%)
Mutual labels:  excel, poi
refinery
Refinery is a tool to extract and transform semi-structured data from Excel spreadsheets of different layouts in a declarative way.
Stars: ✭ 30 (-64.71%)
Mutual labels:  excel, poi
ExcelUtil
Excel utility for Java to read and write data in declarative way.
Stars: ✭ 27 (-68.24%)
Mutual labels:  excel, poi
poi-mapper
Model to Excel, Excel to Model mapper based on apache poi, java reflection
Stars: ✭ 13 (-84.71%)
Mutual labels:  excel, poi
excel2javabeans
convert excel rows to javabeans and vice visa
Stars: ✭ 16 (-81.18%)
Mutual labels:  excel, poi
ExcelReads
ExcelReads(简单Excel通用读写器)
Stars: ✭ 46 (-45.88%)
Mutual labels:  excel, poi
Poi
☀️ Read and Write Excel file using Java and Apache POI
Stars: ✭ 321 (+277.65%)
Mutual labels:  excel, poi
Autopoi
AutoPOI 功能如同名字auto,追求的就是自动化,让一个没接触过poi的人员,可以傻瓜化的快速实现Excel导入导出、Word模板导出、可以仅仅5行代码就可以完成Excel的导入导出。
Stars: ✭ 213 (+150.59%)
Mutual labels:  excel, poi
hadoopoffice
HadoopOffice - Analyze Office documents using the Hadoop ecosystem (Spark/Flink/Hive)
Stars: ✭ 56 (-34.12%)
Mutual labels:  excel, poi
npoi
a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Stars: ✭ 4,493 (+5185.88%)
Mutual labels:  excel, poi
lisp-xl
Common Lisp Microsoft XLSX (Microsoft Excel) loader for arbitrarily-sized / big-size files
Stars: ✭ 27 (-68.24%)
Mutual labels:  excel
exoffice
Library to parse common excel formats (xls, xlsx, csv)
Stars: ✭ 31 (-63.53%)
Mutual labels:  excel
hfexcel
JSON to Excel in Python. 🐍 Human Friendly excel creation in python. 📄 easy, advanced and smart api. json to excel conversion support.. ❤️
Stars: ✭ 16 (-81.18%)
Mutual labels:  excel

Simple-Excel

Simply modify and diff Excel sheets in Java

Simple-Excel wraps the Apache POI project with simple Java builders to modify sheets quickly and easily without all the boilerplate.

Use Hamcrest Matchers to compare workbooks and get fast feedback in tests. Comparing two sheets will compare the entire contents. You get a full report of the diff rather than just the first encountered difference.

Modifying an Excel sheet

Add styles, formula and content to cells programmatically via a simple DSL.

@Test
public void shouldReplaceCellsInComplicatedAlternateSyntaxExample() throws IOException {
public void shouldReplaceCellsInComplicatedAlternateSyntaxExample() throws IOException {
    HSSFWorkbook workbook = getWorkbook("shouldReplaceCellsInComplicatedExampleTemplate.xls");
    new PoiWorkbookMutator(workbook)
            .replaceCell(coordinate(C, 5), "Adding")
            .replaceCell(coordinate(D, 11), "a")
            .replaceCell(coordinate(G, 3), "cell")
            .replaceCell(coordinate(J, 10), "total")
            .replaceCell(coordinate(M, 15), 99.99d);

    assertThat(workbook, sameWorkbook(getWorkbook("shouldReplaceCellsInComplicatedExampleTemplateExpected.xls")));
}

A break in the matcher would show something like

java.lang.AssertionError:
Expected: equality of cell "G1"
     but: cell at "G1" contained <"Text"> expected <99.99D>
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)

Adding Styling

Define some styles to reuse

private final Border border = border(top(NONE), right(THIN_SOLID), bottom(THIN_SOLID), left(THIN_SOLID));
private final DataFormat numberFormat = dataFormat("#,##0.00");

Next create your Cell with style information.

Cell cell = new DoubleCell(99.99d, aStyle().with(border).with(numberFormat));

and add it to a Row.

HashMap<ColumnIndex, Cell> columns = new HashMap<ColumnIndex, Cell>() {{
    put(column(A), cell);
}};
Row row = new Row(columns);

add your row to the workbook.

new PoiWorkbookMutator(workbook).mutator.appendRowToFirstSheet(row);

Using Matchers

To get more detailed output from mismatches, be sure to use MatcherAssert.assertThat from Hamcrest rather than the vanilla JUnit version (org.junit.Assert.assertThat). If you use the JUnit version, you'll get output similar to the following.

java.lang.AssertionError:
Expected: entire workbook to be equal
     got: <org.apache.poi.hssf.usermodel.HSSFWorkbook@6405ce40>

When, using MatcherAssert, you'd see something like this.

java.lang.AssertionError:
Expected: entire workbook to be equal
     but: cell at "C14" contained <"bananas"> expected <nothing>,
          cell at "C15" contained <"1,850,000 EUR"> expected <"1,850,000.00 EUR">,
          cell at "D16" contained <nothing> expected <"Tue Sep 04 06:30:00">
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)

Caveats

  • Currently, matching doesn't take into account styling. A cell is equal to another regardless of style. If one has a border for example, and the other doesn't but they have the same values, they are considered equal.

Download

Available for manual download via my Maven repository or add the repository to your 'pom.xml'.

<repositories>
    <repository>
        <id>bad.robot</id>
        <name>bad.robot repository on robotooling</name>
        <url>https://robotooling.com/maven/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

Then add a dependency.

<dependency>
    <groupId>bad.robot</groupId>
    <artifactId>simple-excel</artifactId>
    <version>1.2</version>
    <scope>compile</scope>
</dependency>

For more tools, see robotooling.com and visit my blog.

Releasing

Take a look at the release readme.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].