java office库_面向对象的Java库,用于读写Microsoft Office Excel电子表格

本文介绍了如何使用excel-io库,这是一个基于Apache POI的Java库,提供了一个面向对象的接口,方便地创建和读取Microsoft Office Excel电子表格。通过示例展示了如何创建新的工作簿、修改现有工作簿以及自定义单元格样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Excel-io

Java excel library (Apache POI inside)

68747470733a2f2f706e672e69636f6e73382e636f6d2f636f6c6f722f3130302f3030303030302f6d732d657863656c2e706e67

687474703a2f2f7777772e656c6567616e746f626a656374732e6f72672f62616467652e737667687474703a2f2f7777772e72756c746f722e636f6d2f622f5661746176756b2f657863656c2d696f

68747470733a2f2f7472617669732d63692e6f72672f5661746176756b2f657863656c2d696f2e7376673f6272616e63683d6d6173746572687474703a2f2f6a617661646f632e696f2f62616467652f68722e636f6d2e7667762f657863656c2d696f2e73766768747470733a2f2f696d672e736869656c64732e696f2f6d6176656e2d63656e7472616c2f762f68722e636f6d2e7667762f657863656c2d696f2e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667

68747470733a2f2f636f6465636f762e696f2f67682f5661746176756b2f657863656c2d696f2f6272616e63682f6d61737465722f67726170682f62616467652e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f6e61722d6f6b2d677265656e2e737667

This is an object-oriented java library for reading and writing Microsoft Office Excel spreadsheets. It is a wrapper around Apache POI that provides elegant and user friendly interface for creating Excel documents.

How to use. Latest version here

hr.com.vgv

excel-io

Java version required: 1.8+.

Create spreadsheet

new XsWorkbook(

new XsSheet(

new XsRow()

.with(new TextCells("name", "email", "salary", "bonus", "total"))

.with(

new XsStyle(

new ForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()),

new FillPattern(FillPatternType.SOLID_FOREGROUND)

)

),

new XsRow()

.with(new TextCells("Steve Hook", "steve.hook@gmail.com"))

.with(new NumberCells(160000.0, 35337.6))

.with(new FormulaCell("SUM(C3:D3)")

.with(

new XsStyle(

new ForegroundColor(IndexedColors.RED.getIndex()),

new FillPattern(FillPatternType.SOLID_FOREGROUND)

)

)

)

.with(new XsProps<>(new Height((short) 500)))

)

).saveTo("Test.xlsx");

This is how the result looks like: 6bebc367138966f1024e4280c78a42af.png

Read and modify spreadsheet

Read from "Test.xlsx" file and modify cell int the second row/first column.

new XsWorkbook("Test.xlsx")

.with(new XsSheet.ReadFrom(0)

.with(

new XsRow(2,

new TextCell(1, "UPDATED")

)

)

).saveTo("Updated.xlsx");

Custom styles

You can create custom cells/rows/sheets:

new XsWorkbook(

new XsSheet(

new MyCustomRow("Boris", "Miksic", "ID:2450"),

new MyCustomRow("Mirko", "Mirkic", "ID:1690")

)

).saveTo("Test.xlsx");

Just extend appropriate template class and pass custom row/cell object to its constructor:

private static class MyCustomRow extends RowTemplate {

public MyCustomRow(final String name, final String surname, final String id) {

super(

new XsRow()

.with(new TextCells(name, surname))

.with(new MyGreyCell(new TextCell(id)))

);

}

}

private static class MyGreyCell extends CellTemplate {

public MyGreyCell(final ECell cell) {

super(cell.with(

new XsStyle(

new ForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()),

new FillPattern(FillPatternType.SOLID_FOREGROUND)

)

));

}

}

The result:

df933a934c3ff0c540795be05a1a9a58.png

Contribution

You can contribute by forking the repo and sending a pull request. Make sure your branch builds without any warnings/issues:

mvn clean install -Pqulice

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值