package com.casic.common.detector.gd.utils

import com.casic.common.detector.gd.bean.MarkerLocalBean
import jxl.Workbook
import jxl.read.biff.BiffException
import java.io.File

object ExcelTool {
    fun read(filePath: String): ArrayList<MarkerLocalBean> {
        val result = ArrayList<MarkerLocalBean>()
        try {
            val workbook = Workbook.getWorkbook(File(filePath))
            val sheet = workbook.getSheet(0)

            for (i in 1 until sheet.rows) {
                val marker = MarkerLocalBean()
                marker.pipelineType = sheet.getCell(0, i).contents
                marker.pipelineDiameter = sheet.getCell(1, i).contents
                marker.pipelineMaterial = sheet.getCell(2, i).contents
                marker.buryMethod = sheet.getCell(3, i).contents
                marker.buryDepth = sheet.getCell(4, i).contents
                marker.area = sheet.getCell(5, i).contents
                marker.line = sheet.getCell(6, i).contents
                marker.road = sheet.getCell(7, i).contents
                marker.constructTime = sheet.getCell(8, i).contents
                marker.owner = sheet.getCell(9, i).contents
                marker.objectId = sheet.getCell(10, i).contents
                marker.markerId = sheet.getCell(11, i).contents
                marker.markerType = sheet.getCell(12, i).contents
                marker.markerDepth = sheet.getCell(13, i).contents
                marker.installationDept = sheet.getCell(14, i).contents
                marker.lng = sheet.getCell(15, i).contents
                marker.lat = sheet.getCell(16, i).contents
                marker.updateTime = sheet.getCell(17, i).contents
                marker.remark = sheet.getCell(18, i).contents
                marker.underlyingPipelineType = sheet.getCell(19, i).contents
                marker.underlyingPipelineDepth = sheet.getCell(20, i).contents
                marker.underlyingPipelineDiameter = sheet.getCell(21, i).contents
                marker.underlyingPipelineMaterial = sheet.getCell(22, i).contents
                marker.objectType = sheet.getCell(23, i).contents
                marker.color = sheet.getCell(24, i).contents
                marker.imagePath = sheet.getCell(25, i).contents

                result.add(marker)
            }
            workbook.close()
        } catch (e: BiffException) {
            e.printStackTrace()
        }
        return result
    }
}