Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate formatted XLS with JAVA

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use JAVA to generate formatted XLS, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Is there any convenient class library for exporting formatted Excel in Java? Some of the data are as follows:

ORDERID CUSTOM ORDERDATE FREIGHT

10262 Learnthe kernel trade 1996-07-22 48.29

10263 Resources are people 1996-07-23 146.06

10264 Wuzhou trust 2007-12-18 3.67

10265 The hao 1996-07-25 55.28

10266 Upgrade the enterprise 1996-07-26 25.73

...

The export Excel styles are as follows:

Java generally makes use of Jakarta POI HSSF API components (components used to manipulate Excel). The main parts include Excel objects, styles and formats, and auxiliary operations. But it's too long to write, and the code goes something like this:

...

HSSFWorkbook workbook = new HSSFWorkbook ()

HSSFSheet sheet = workbook.createSheet (title)

HSSFRow rowm = sheet.createRow (0)

HSSFCellStyle columnTopStyle=this.getColumnTopStyle (workbook)

HSSFCellStyle style=this.getStyle (workbook)

Sheet.addMergedRegion (new CellRangeAddress (0,1,0, (rowName.length-1)

CellTitle.setCellStyle (columnTopStyle)

CellTitle.setCellValue (title)

For (int n = 0; n

< columnNum; n++) { HSSFCell cellRowName = rowRowName.createCell(n); cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING); ... } ... Excel导出,用集算器结合润乾报表会简单很多,首先,报表工具设计一张模板,它底层把 POI做了完整封装,可以保持Excel格式不变。 然后,在集算器中执行报表的函数,它把报表运算过程做了封装,这样就可以自动导出各类风格、无失真的Excel。比如上面问题仅需5行: A 1 =file("orders.txt":"UTF-8").import@t() 2 >

Report_config ("/ raqsoftConfig.xml")

three

= report_open ("ORDER.rpx")

four

= report_run (A3X A1: "ds1")

five

= report_exportXls@x (A3, "ORDER.xlsx")

In fact, there are many situations where it is not convenient to export Excel with Java, such as grouping, crossover, Chinese-style complex format reports and so on.

On how to use JAVA to generate formatted XLS to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report