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 embed java to realize complex Excel data storage

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

Share

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

This article shows you how to embed java to achieve complex Excel data storage, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

General routine method: first use third-party class libraries such as POI or HSSFWorkbook to structure its table data, and then write it to the database with SQL statements. Because there is no table object in Java, it is always realized by using collection and entity class (hard coding). If you encounter a table with a complex format, it is difficult to parse, the workload will be doubled, and the code is not only lengthy, but also difficult to be universal.

For example, to deal with a scenario where the database table Logistics has three fields: Shippers, Region, and Quantity. Parse the following Excel table and enter it into the library:

The effect after entering the library:

The Java code should probably be written like this:

...

File target = new File (filepath, filename)

FileInputStream fi = new FileInputStream (target)

HSSFWorkbook wb = new HSSFWorkbook (fi)

HSSFSheet sheet = wb.getSheetAt (sheetnum)

Int rowNum = sheet.getLastRowNum () + 1

For (int I = startrow; I < rowNum; iTunes +) {

PageData varpd = new PageData ()

HSSFRow row = sheet.getRow (I)

Int cellNum = row.getLastCellNum ()

...

}

...

List listPd = (List) ObjectExcelRead.readExcel (filePath, fileName, 3,0,0)

For (int iTuno Bandi)

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