From eb3dd00b0b7fcda477229d518d250f9c842b790b Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 21 十月 2025 17:45:44 +0800
Subject: [PATCH] 2025.10.21 1. 走航季度报告相关数据计算逻辑调整
---
src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt | 35 +++++++++++++++++++++++++++--------
1 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt
index 6d598ef..c73f36b 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/ExcelUtil.kt
@@ -1,14 +1,13 @@
package com.flightfeather.uav.common.utils
-import com.flightfeather.uav.common.exception.ResponseErrorException
+import com.flightfeather.uav.common.exception.BizException
+import org.apache.poi.hssf.usermodel.HSSFRow
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.util.CellRangeAddress
import org.apache.poi.xssf.streaming.SXSSFWorkbook
import org.apache.poi.xssf.usermodel.XSSFRow
import org.apache.poi.xssf.usermodel.XSSFWorkbook
-import org.jetbrains.kotlin.incremental.isJavaFile
-import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
@@ -37,15 +36,18 @@
* @param headerCheck 鏂囦欢棣栬妫�鏌ュ洖璋�
* @param onRow 鍗曡鍐呭鍥炶皟锛屼粠绗簩琛屽紑濮�
*/
- fun read(file: File, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean {
- if (!file.exists() || !file.isFile) throw ResponseErrorException("it's not a normal file!")
+ fun readXLXS(file: File, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean {
+ if (!file.exists() || !file.isFile) throw BizException("it's not a normal file!")
if (!file.extension.equals("xls", ignoreCase = true) || !file.extension.equals("xlsx", ignoreCase = true)) {
- throw ResponseErrorException("file's extension name should be xls or xlsx!")
+ throw BizException("file's extension name should be xls or xlsx!")
}
- return read(FileInputStream(file), headerCheck, onRow)
+ return readXLXS(FileInputStream(file), headerCheck, onRow)
}
- fun read(input: InputStream, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean {
+ /**
+ * 鍖呮嫭 .xlsx 鏂囦欢
+ */
+ fun readXLXS(input: InputStream, headerCheck: (header: XSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean {
val workbook = XSSFWorkbook(input)
val sheet1 = workbook.getSheetAt(0)
val header = sheet1.getRow(sheet1.topRow.toInt())
@@ -60,6 +62,23 @@
}
/**
+ * 鍖呮嫭 .xls .csv 鏂囦欢
+ */
+ fun readXLS(input: InputStream, headerCheck: (header: HSSFRow) -> Boolean, onRow: (row: Row) -> Unit): Boolean {
+ val workbook = HSSFWorkbook(input)
+ val sheet1 = workbook.getSheetAt(0)
+ val header = sheet1.getRow(sheet1.topRow.toInt())
+ return if (headerCheck(header)) {
+ // 鑾峰彇杩唬鍣ㄥ苟鍘婚櫎绗竴琛屾爣棰�
+ val iterator = sheet1.rowIterator().also { it.next() }
+ iterator.forEach { onRow(it) }
+ true
+ } else {
+ false
+ }
+ }
+
+ /**
* 鑷姩澶勭悊琛屽悎骞舵暟鎹�
*/
fun write2(heads: List<String>, contents: List<Array<Any>>, workbook: SXSSFWorkbook, sheetName: String) {
--
Gitblit v1.9.3