Changeset 7818
- Timestamp:
- 03/12/08 01:46:20 (5 years ago)
- Location:
- lang/scala/sandbox/src/jp/ryugate/apache
- Files:
-
- 2 modified
-
POI.scala (modified) (7 diffs)
-
POISpecification.scala (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/ryugate/apache/POI.scala
r7772 r7818 3 3 /** 4 4 * POI wrapper 5 * 2008/ 2/185 * 2008/3/12 6 6 */ 7 7 object POI { … … 25 25 */ 26 26 class MyBook(hssf_book:HSSFWorkbook) { 27 def sheet(index:int ) = hssf_book.getSheetAt(index-1) 27 def sheet(index:int ) = hssf_book.getSheetAt(index-1) // index start from 1 28 28 def sheet(name:String) = hssf_book.getSheet(name) match { 29 29 case null => throw new NoSuchElementException(name + "(Sheet not found)") … … 51 51 */ 52 52 class MySheet(hssf_sheet:HSSFSheet) { 53 def row(ri:int) = hssf_sheet.getRow(ri-1) 53 def row(ri:Int) = hssf_sheet.getRow(ri-1) match { // index start from 1 54 case null => hssf_sheet.createRow(ri-1) 55 case row => row 56 } 54 57 def col(ci:int) = new Col(this, ci) 55 58 … … 77 80 def each[V](f:HSSFRow => V) = eachRows(0 to getLastRowNum)(f) 78 81 82 def getLastRowNum = hssf_sheet.getLastRowNum 83 79 84 //-------------------------------------------- 80 def createRow(rownum:int) = hssf_sheet.createRow(rownum-1) 81 82 def getLastRowNum = hssf_sheet.getLastRowNum 85 def setCell(ri:Int, ci:Int, value:String, encoding:Short):HSSFCell = row(ri).setCell(ci, value, encoding) 86 def setCell(ri:Int, ci:Int, value:String):HSSFCell = row(ri).setCell(ci, value) 83 87 } 84 88 implicit def HSSFSheetToExtSheet(sheet:HSSFSheet) = new MySheet(sheet) … … 88 92 */ 89 93 class MyRow(hssf_row:HSSFRow) { 90 def get(cellnum:int) = hssf_row match {94 def get(cellnum:int) = hssf_row.getCell((cellnum-1).toShort) match { // index start from 1 91 95 case null => None 92 case _ => hssf_row.getCell((cellnum-1).toShort) match { 93 case null => None 94 case v => new Some(v) 95 } 96 case v => new Some(v) 96 97 } 97 98 … … 117 118 118 119 //-------------------------------------------- 119 def createCell(cellnum:int) = hssf_row.createCell(cellnum.toShort) 120 121 def setCell(cellnum:int, value:String, encoding:Short):HSSFCell = { 122 val cell = hssf_row.createCell(cellnum.toShort) 120 def setCell(ci:int, value:String, encoding:Short):HSSFCell = { // index start from 1 121 val cell = hssf_row.createCell((ci-1).toShort) 123 122 cell.setEncoding(encoding) 124 123 cell.setCellValue(value) … … 152 151 153 152 def each[V](f:HSSFCell => V) = eachCells(0 to sheet.getLastRowNum)(f) 153 154 //-------------------------------------------- 155 def setCell(cellnum:int, value:String, encoding:Short):HSSFCell = sheet.row(cellnum).setCell(colIdx, value, encoding) 156 def setCell(cellnum:int, value:String):HSSFCell = sheet.row(cellnum).setCell(colIdx, value) 154 157 } 155 158 -
lang/scala/sandbox/src/jp/ryugate/apache/POISpecification.scala
r7772 r7818 11 11 import org.apache.poi.hssf.usermodel.HSSFCell 12 12 import org.apache.poi.hssf.usermodel.HSSFCell._ 13 import org.apache.poi.hssf.usermodel.HSSFCellStyle 13 14 14 15 import java.lang._ 15 16 import java.io.FileInputStream 17 import java.io.FileOutputStream 16 18 17 19 "POI module" should { … … 50 52 sheet1.cell(100,100) must throwException(new NoSuchElementException) 51 53 52 sheet1.row(100) must beNull54 sheet1.row(100) must notBeNull 53 55 sheet1.col(100) must notBeNull 54 56 … … 65 67 "create and get Sheet" in { 66 68 val bk = new HSSFWorkbook 67 bk.createSheet("test") 69 val style = bk.createCellStyle 70 style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM) 71 72 val sheet = bk.createSheet("test") 68 73 bk.sheet(1) must notBeNull 69 bk.sheet("hoge") must throwException(new NoSuchElementException) 74 sheet.row(1).setCell(1,"hoge").setCellStyle(style) 75 sheet.col(2).setCell(2,"piyo").setCellStyle(style) 76 sheet.setCell(3,3,"HOGE").setCellStyle(style) 77 78 bk.write(new FileOutputStream("testdata/testoutput.xls")) 79 70 80 } 71 81
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)