require '../../poi-3.0.1-FINAL-20070705.jar'
include Java
include_class java.io.FileInputStream
include_class Java::org.apache.poi.hssf.usermodel.HSSFWorkbook
include_class Java::org.apache.poi.hssf.usermodel.HSSFSheet
include_class Java::org.apache.poi.hssf.usermodel.HSSFRow
include_class Java::org.apache.poi.hssf.usermodel.HSSFCell
class ExcelWorkBook
def initialize(xlsFile)
input = FileInputStream.new(xlsFile)
@hssfworkbook = HSSFWorkbook.new(input)
end
def worksheet(sheet_position)
ExcelWorkSheet.new(@hssfworkbook.getSheetAt(sheet_position),sheet_position)
end
class ExcelWorkSheet
def initialize(hssfworksheet, sheet_position)
@index = sheet_position
@hssfworksheet = hssfworksheet
end
def row_at(rownumber)
return Row.new(@hssfworksheet.getRow(rownumber))
end
def rows
rows = []
for row in @hssfworksheet.rowIterator
rows << Row.new(row)
end
rows
end
class Row
def initialize(hssfrow)
@hssfrow = hssfrow
end
def value_at(columnindex)
cell = @hssfrow.getCell(columnindex)
if(cell == nil)
''
elsif(HSSFCell::CELL_TYPE_NUMERIC == cell.getCellType())
cell.getNumericCellValue()
elsif(HSSFCell::CELL_TYPE_STRING == cell.getCellType())
cell.getRichStringCellValue()
end
end
end
end
end
Subscribe to Post Comments [Atom]
I am passionate about making Better Software Solutions,that helps businesses to stay agile, by applying Agile,Lean and Systems Thinking principles. Also I grow coffee,spices and in general has big interest in pesticide free food!
Subscribe to
Posts [Atom]