Changeset 6747 for lang/scala/sandbox
- Timestamp:
- 02/16/08 00:36:57 (10 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/ryugate/apache/POI.scala
r6646 r6747 13 13 import org.apache.poi.hssf.usermodel.HSSFCell 14 14 import org.apache.poi.hssf.usermodel.HSSFCell._ 15 16 private def gets[T](f:int => T, n:int*) 17 = n.foldLeft(List[T]()){(acc, i) => f(i) :: acc}.reverse 18 private def eachWithIndex[T](f:(int*) => List[T], f2:(T,int) => Unit, arg:int*) 19 = f(arg:_*).zipWithIndex.foreach{case (row,idx) => f2(row,idx)} 15 20 16 21 /** … … 18 23 */ 19 24 class Book(book:HSSFWorkbook) { 25 def this() = this(new HSSFWorkbook()) 20 26 def this(is:InputStream) = this(new HSSFWorkbook(is)) 21 27 def this(ist:FileInputStream) = this(new HSSFWorkbook(ist)) 22 28 def this(filename:String) = this(new FileInputStream(filename)) 23 def this() = this(new HSSFWorkbook())24 29 25 def getSheet(index:int )= new Sheet(book.getSheetAt(index))26 def getSheet(name:String) = new Sheet(book.getSheet(name))30 def getSheet(index:int ) = new Sheet(book.getSheetAt(index)) 31 def getSheet(name:String) = new Sheet(book.getSheet(name)) 27 32 28 def sheetWith(index:int)(f:Sheet => Unit):Unit = f(getSheet(index)) 33 def sheet(index:int ) = getSheet(index) 34 def sheet(name:String) = getSheet(name) 35 36 def sheets(idxs:int* ) = gets(sheet, idxs:_*) 37 def sheets(range:Range) = gets(sheet, range:_*) 29 38 30 def eachSheets(range:Range)(f:Sheet => Unit):Unit = range.foreach{i => f(new Sheet(book.getSheetAt(i)))} 39 def sheetWith(index:int )(f:Sheet => Unit):Unit = f(getSheet(index)) 40 def sheetWith(name:String)(f:Sheet => Unit):Unit = f(getSheet(name)) 41 42 def eachSheets(idxs:int* )(f:Sheet => Unit):Unit = sheets(idxs:_* ).foreach{f(_)} 43 def eachSheets(range:Range)(f:Sheet => Unit):Unit = sheets(range:_*).foreach{f(_)} 44 45 def eachSheetsWithIndex(idxs:int* )(f:(Sheet,int) => Unit) = eachWithIndex(sheets, f, idxs:_*) 46 def eachSheetsWithIndex(range:Range)(f:(Sheet,int) => Unit) = eachWithIndex(sheets, f, range:_*) 31 47 32 48 def each(f:Sheet => Unit):Unit = eachSheets(0 to book.getNumberOfSheets-1)(f) 33 49 50 //-------------------------------------------- 34 51 def createSheet() = new Sheet(book.createSheet) 35 52 def createSheet(name:String) = new Sheet(book.createSheet(name)) … … 41 58 class Sheet(sheet:HSSFSheet) { 42 59 def getRow(rownum:int) = new Row(sheet.getRow(rownum)) 43 def row(rownum:int) = getRow(rownum)44 45 60 def getCol(colnum:int) = new Col(sheet, colnum) 46 61 62 def row(rownum:int) = getRow(rownum) 63 def col(colnum:int) = getCol(colnum) 64 47 65 def getCell(row:int,col:int) = getRow(row).getCell(col) 66 def cell(row:int,col:int) = getCell(row,col) 48 67 49 def gets[T](f:int => T, n:Array[int]) = n.foldLeft(List[T]()){(acc, i) => f(i) :: acc}.reverse50 def rows(rs:int*) = gets(getRow, rs.toArray)51 def rows(range:Range ) = gets(getRow, range.toArray)52 def cols( cs:int*) = gets(getCol, cs.toArray)68 def rows(rowIdxs:int*) = gets(getRow, rowIdxs:_*) 69 def cols(colIdxs:int*) = gets(getCol, colIdxs:_*) 70 def rows(range:Range ) = gets(getRow, range:_*) 71 def cols(range:Range ) = gets(getCol, range:_*) 53 72 54 def rowWith(rownum:int)(f:Row => Unit):Unit = f(getRow(rownum)) 73 def rowWith(num:int)(f:Row => Unit):Unit = f(getRow(num)) 74 def colWith(num:int)(f:Col => Unit):Unit = f(getCol(num)) 55 75 56 def eachRows(range:Range)(f:Row => Unit) = range.foreach{i => f(new Row(sheet.getRow(i)))} 57 def eachCols(cs:int*)(f:Col => Unit) = cs.foreach {col => f(new Col(sheet, col))} 76 def eachRows(rowIdxs:int*)(f:Row => Unit) = rows(rowIdxs:_*).foreach{f(_)} 77 def eachCols(colIdxs:int*)(f:Col => Unit) = cols(colIdxs:_*).foreach{f(_)} 78 def eachRows(range:Range )(f:Row => Unit) = rows(range ).foreach{f(_)} 79 def eachCols(range:Range )(f:Col => Unit) = cols(range ).foreach{f(_)} 80 81 def eachRowsWithIndex(idxs:int* )(f:(Row,int) => Unit) = eachWithIndex(rows, f, idxs:_*) 82 def eachColsWithIndex(idxs:int* )(f:(Col,int) => Unit) = eachWithIndex(cols, f, idxs:_*) 83 def eachRowsWithIndex(range:Range)(f:(Row,int) => Unit) = eachWithIndex(rows, f, range:_*) 84 def eachColsWithIndex(range:Range)(f:(Col,int) => Unit) = eachWithIndex(cols, f, range:_*) 58 85 59 86 def each(f:Row => Unit):Unit = eachRows(0 to sheet.getLastRowNum)(f) 60 87 88 //-------------------------------------------- 61 89 def createRow(rownum:int) = new Row(sheet.createRow(rownum)) 62 90 } … … 68 96 def getCell(cellnum:int) = new Cell(row.getCell(cellnum.toShort)) 69 97 def cell(cellnum:int) = getCell(cellnum) 70 def cells(cs:int*) = cs.foldLeft(List[Cell]()){(acc,cell) => getCell(cell) :: acc}.reverse 98 99 def cells(idxs:int* ) = gets(getCell, idxs:_*) 100 def cells(range:Range) = gets(getCell, range:_*) 71 101 72 def eachCells(range:Range)(f:Cell => Unit) = range.foreach{i => f(new Cell(row.getCell(i.toShort)))} 73 def eachCells(cols:int*)(f:Cell => Unit) = cols.foreach{i => f(new Cell(row.getCell(i.toShort)))} 74 102 def eachCells(idxs:int* )(f:Cell => Unit) = cells(idxs:_* ).foreach{f(_)} 103 def eachCells(range:Range)(f:Cell => Unit) = cells(range:_*).foreach{f(_)} 104 105 def eachCellsWithIndex(idxs:int* )(f:(Cell,int) => Unit) = eachWithIndex(cells, f, idxs:_*) 106 def eachCellsWithIndex(range:Range)(f:(Cell,int) => Unit) = eachWithIndex(cells, f, range:_*) 107 75 108 def each(f:Cell => Unit):Unit = eachCells(1 to row.getLastCellNum-1)(f) 76 109 110 //-------------------------------------------- 77 111 def createCell(cellnum:int) = new Cell(row.createCell(cellnum.toShort)) 78 112 … … 93 127 def getCell(row:int) = new Cell(sheet.getRow(row).getCell(col.toShort)) 94 128 def cell(row:int) = getCell(row) 129 130 def cells(idxs:int* ) = gets(getCell, idxs:_*) 131 def cells(range:Range) = gets(getCell, range:_*) 95 132 96 def eachCells(rows:int*)(f:Cell => Unit) = rows.foreach{i => f(getCell(i))} 133 def eachCells(idxs:int* )(f:Cell => Unit) = cells(idxs:_* ).foreach{f(_)} 134 def eachCells(range:Range)(f:Cell => Unit) = cells(range:_*).foreach{f(_)} 135 136 def eachCellsWithIndex(idxs:int* )(f:(Cell,int) => Unit) = eachWithIndex(cells, f, idxs:_*) 137 def eachCellsWithIndex(range:Range)(f:(Cell,int) => Unit) = eachWithIndex(cells, f, range:_*) 138 139 def each(f:Cell => Unit):Unit = eachCells(1 to sheet.getLastRowNum-1)(f) 97 140 } 98 141 … … 102 145 class Cell(cell:HSSFCell) { 103 146 def getNumericCellValue = cell.getNumericCellValue 147 104 148 def getCellValue = { 105 149 cell.getCellType match {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)