Rahul2692
Rahul2692

Reputation: 344

XLS throwing java.lang.ClassNotFoundException: org.apache.poi.hssf.util.HSSFColor$BLACK

I'm having problems trying to open an XLS file with Apache POI. I am integrating HSSF in rails application.

My code is like:

require "rjb"

  Rjb::add_jar(File.expand_path('demo/poi-3.9/poi-3.9-20121203.jar'))
  Rjb::add_jar(File.expand_path('demo/poi-3.9/commons-codec-1.7.jar'))

  Black = Rjb::import 'org.apache.poi.hssf.util.HSSFColor$BLACK'
  HSSFCell = Rjb::import 'org.apache.poi.hssf.usermodel.HSSFCell'
  HSSFCellStyle = Rjb::import 'org.apache.poi.hssf.usermodel.HSSFCellStyle'
  HSSFFont = Rjb::import 'org.apache.poi.hssf.usermodel.HSSFFont'
  HSSFWorkbook = Rjb::import 'org.apache.poi.hssf.usermodel.HSSFWorkbook'
  IOUtils = Rjb::import 'org.apache.poi.util.IOUtils'
  JavaFont = Rjb::import 'java.awt.Font'
  FileInputStream = Rjb::import 'java.io.FileInputStream'
  FileOutputStream = Rjb::import 'java.io.FileOutputStream'

def self.export_xls (params)
    file = "tmp/#{Time.now.to_formatted_s(:number)}_#{abc}.xls"
    @book = HSSFWorkbook.new
    @sheet1 = @book.createSheet l(:report_name)
    @drawing = @sheet1.createDrawingPatriarch()
    @number_of_column = 0
    @number_of_column_to_merge = 10
    black = Black.index

    @styleTableTitle = @book.createCellStyle()       
    @styleTableTitle.setBorderBottom(HSSFCellStyle.BORDER_THIN)
    @styleTableTitle.setBottomBorderColor(black)

    out = FileOutputStream.new("#{Rails.root}/" + file)
    @book.write(out)
    out.close()
    file
end

Exception throw:

RuntimeError (java.lang.ClassNotFoundException: org.apache.poi.hssf.util.HSSFColor$BLACK)

Imported jars (Apache POI):

poi-3.9-20121203 poi-3.7-20101029 commons-codec-1.7

Upvotes: 1

Views: 2071

Answers (0)

Related Questions