Trong ứng dụng này, chúng tôi có thể xuất dữ liệu vào một tệp Excel từ cơ sở dữ liệu [cơ sở dữ liệu H2] trong Spring Boot. & NBSP; Chúng tôi đang sử dụng thư viện Apache POI để xuất Excel.We are using the Apache POI library for exporting excel.
Định cấu hình Apache Poi
org.apache.poi
poi
5.1.0
org.apache.poi
poi-ooxml
5.1.0
Quá trình phát triển:
1. & nbsp; Giữ Eclipse IDE sẵn sàng
2
3. Xác định kết nối cơ sở dữ liệu trong application.properies
4. Tạo lớp thực thể
5. Tạo một kho lưu trữ
6. Tạo dịch vụ
7. & nbsp; Tạo lớp Trình tạo tệp Excel
8. & nbsp; Tạo một lớp bộ điều khiển
9. & nbsp; Tạo trang xem trên thư mục tĩnh của dữ liệu xuất sang dự án Excel
10. Tạo CommandRinerunner trên lớp SpringBootApplication
11. Chạy dự án
1. & nbsp; Giữ Eclipse IDE sẵn sàng
2[Select Spring Web, Spring Data JPA, and H2 Database dependencies]
Download the Excel File
10. Tạo CommandRinerunner trên lớp SpringBootApplication 11. Chạy dự án
0
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.6.3
com.example
Export_Excel_Spring_Boot_Example
0.0.1-SNAPSHOT
Export_Excel_Spring_Boot_Example
Demo project for Spring Boot
11
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-web
com.h2database
h2
runtime
org.apache.poi
poi
5.1.0
org.apache.poi
poi-ooxml
5.1.0
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
2//localhost:8888/demo/h2-console/" for the testing table to be created and whether data is inserted properly or not.
Sự phụ thuộc maven
7. Tạo lớp tạo tệp Excel
→ XSSFWorkbook đang tạo một sổ làm việc là tệp excel của chúng tôi.
→ Chúng tôi đang tạo một thể hiện của XSSFWorkbook sau đó chúng tôi đang gọi phương thức "createdesheet []" để tạo tệp excel có tên.
→ Chúng tôi đang tạo các hàng và ô của một tờ Excel.
→ Sau đó, chúng tôi đang viết dữ liệu vào bảng Excel.