Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.oak.excel
- import java.io.{File, FileInputStream}
- import org.apache.poi.ss.usermodel.{Cell, Sheet, Workbook}
- import org.apache.poi.xssf.usermodel.XSSFWorkbook
- case class MpdLink(mpdTask: String, ammTask: String,descr: String, accDescr:Option[String],prepHH: Double, taskHH: Double)
- class MpdReader {
- def read(mpd: String) {
- val inputStream: FileInputStream = new FileInputStream(new File(mpd))
- val workbook: Workbook = new XSSFWorkbook(inputStream)
- val firstSheet:Sheet = workbook.getSheetAt(1)
- val iterator = firstSheet.rowIterator()
- val dump = scala.collection.mutable.ArrayBuffer[MpdLink]()
- while(iterator.hasNext){
- val row = iterator.next
- val prepHH = setType( row.getCell(12) )
- val taskHH = setType( row.getCell(13) )
- val descr = setType( row.getCell(6) )
- if( isDouble( taskHH ) && isDouble( prepHH ) )
- dump.+=(MpdLink(
- setType( row.getCell(1) ),
- setType( row.getCell(9) ),
- descr,
- accessRemark(descr),
- prepHH.toDouble,
- taskHH.toDouble
- ))
- }
- dump.foreach(m=> println(m.accDescr))
- workbook.close()
- inputStream.close()
- }
- def setType(cell: Cell): String =
- if( cell != null ) cell.getCellType match {
- case Cell.CELL_TYPE_STRING => cell.getStringCellValue
- case Cell.CELL_TYPE_NUMERIC => cell.getNumericCellValue.toString
- case Cell.CELL_TYPE_BLANK => ""
- case _ => ""
- } else ""
- def isDouble(cell: String): Boolean = cell.matches("[0-9.]+")
- def accessRemark(descr: String): Option[String] = {
- val rx = "ДОСТУП ПРИМЕЧАНИЕ:(.*?)$".r
- for(m <- rx.findFirstIn(descr)) yield m
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement