1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cn.flightfeather.supervision.business.location
 
import cn.flightfeather.supervision.common.utils.DateUtil
import cn.flightfeather.supervision.common.utils.ExcelUtil
import cn.flightfeather.supervision.domain.ds1.entity.Scense
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import java.io.File
import java.io.FileOutputStream
import java.util.*
 
/**
 *
 * @date 2024/10/24
 * @author feiyu02
 */
class UtilExcelDistance(head: List<Array<Any>>) {
 
    private val heads = mutableListOf<Array<Any>>()
    private val contents = mutableListOf<Array<Any>>()
    var index = 1
 
    init {
        heads.addAll(head)
    }
 
    fun reset() {
        index = 1
        contents.clear()
    }
 
    fun addRow(row: List<Any>) {
        contents.add(row.toTypedArray())
    }
 
    fun updateLastRow(index: Int, cell: Any) {
        contents.last()[index] = cell
    }
 
    /**
     * 生成一行excel数据
     */
    fun parseRow(row: Array<Any>) {
        contents.add(row)
        index++
    }
 
    fun outPutToFile(districtName: String) {
        val workbook = HSSFWorkbook()
        val fileName = "${districtName}点位距国控点距离-${DateUtil.DateToString(Date(), "yyyy-MM-ddhhmmss")}.xls"
        val filePath = "C:\\work\\工作\\第三方监管\\点位距国控点距离\\$fileName"
        val file = File(filePath)
        if (!file.parentFile.exists()) {
            file.parentFile.mkdirs()
        }
        val out = FileOutputStream(file)
        ExcelUtil.write(heads, contents, workbook)
        workbook.write(out)
        workbook.close()
        out.flush()
        out.close()
    }
}