Apache POI import class HSSFSheet error

Questions and answers on developing, deploying and using plugins and JavaBeans

Apache POI import class HSSFSheet error

Postby deezzub » Mon Jan 12, 2015 11:31 am

I trying to use Apache POI to read and write Excel files. I put the poi-3.11-20141221.jar file to the Servoy Developer plugins folder and created the following function the read an Excel file.

Code: Select all
function excelRead( ) {
   
//   importPackage( org.apache.poi.hssf.usermodel );
   importClass( Packages.org.apache.poi.hssf.usermodel.HSSFSheet );
   importClass( Packages.org.apache.poi.hssf.usermodel.HSSFWorkbook );
   importClass( Packages.java.io.File );
   importClass( Packages.java.io.FileInputStream );
   
   /** @type {java.io.FileInputStream} */
   var file = new FileInputStream( new File( "C:\\test.xls" ) );
   /** @type {org.apache.poi.hssf.usermodel.HSSFWorkbook} */
   var workbook = new org.apache.poi.hssf.usermodel.HSSFWorkbook( file );
}


If I execute the above function, I get the following error.
org.mozilla.javascript.EvaluatorException: Function importClass must be called with a class; had "[JavaPackage org.apache.poi.hssf.usermodel.HSSFSheet]" instead.


HSSFSheet is a class and exists in the library. Does anyone know whats the problem here?
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: Apache POI import class HSSFSheet error

Postby Peter de Groot » Mon Jan 12, 2015 12:01 pm

Hi,

Check out the data plugin at IT2BE

Regards,

Peter
User avatar
Peter de Groot
 
Posts: 215
Joined: Thu Jan 10, 2008 8:38 pm
Location: Not sure...

Re: Apache POI import class HSSFSheet error

Postby deezzub » Mon Jan 12, 2015 12:17 pm

Peter de Groot wrote:Hi,

Check out the data plugin at IT2BE

Regards,

Peter


I know that plugin, but it is not really an answer to my question. ;)
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: Apache POI import class HSSFSheet error

Postby sovanm » Mon Jan 12, 2015 12:44 pm

Hi,

Try keeping the Jar file in bean folder and access it in servoy. Hope that will help you.

Thanks
Sovan
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: Apache POI import class HSSFSheet error

Postby deezzub » Mon Jan 12, 2015 1:00 pm

sovanm wrote:Hi,

Try keeping the Jar file in bean folder and access it in servoy. Hope that will help you.

Thanks
Sovan


Thanks Sovan, that seems to work. :)
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: Apache POI import class HSSFSheet error

Postby sovanm » Mon Jan 12, 2015 1:06 pm

Hi,

Glad that helps.. :)

But..

Code: Select all
org.apache.poi.hssf.usermodel.HSSFWorkbook

This class is already loaded from the plugin/jakarta-poi (I guess with the default excel plugin. You do not need to add it again). That might be the problem here.

I removed the external POI file and your codes seems to be working as well. Please check by removing it may help as well.

Thanks
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: Apache POI import class HSSFSheet error

Postby deezzub » Mon Jan 12, 2015 2:06 pm

sovanm wrote:
Code: Select all
org.apache.poi.hssf.usermodel.HSSFWorkbook

This class is already loaded from the plugin/jakarta-poi (I guess with the default excel plugin. You do not need to add it again). That might be the problem here.

I removed the external POI file and your codes seems to be working as well. Please check by removing it may help as well.

Yes, I saw the jakarta-poi, but if I remove it the problem still exists.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: Apache POI import class HSSFSheet error

Postby patrick » Mon Jan 12, 2015 2:28 pm

When you use the Jasper plugin, you don't have to worry about what gets loaded. POI is part of the Jasper package.

Also, this has been done for you already. Check out the svyUtils module on github: https://github.com/Servoy/svyUtils
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Apache POI import class HSSFSheet error

Postby juan.cristobo » Mon Nov 23, 2015 7:10 pm

with svyUtils you can import excel 97 files (.xls), but I'd like tu use Excel 2007 files (.xlsx). The Apache POI project has XSSF library to do it (https://poi.apache.org/spreadsheet/index.html), but it seems that it isn't implemented in Servoy. Any ideas how to use it?

Thanks,
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am

Re: Apache POI import class HSSFSheet error

Postby patrick » Mon Nov 23, 2015 7:44 pm

I have implemented this for svyUtils, but not yet released. Since it requires some extra libraries, we have a signing issue. I will try to release it before end of year with Servoy signed libraries. You can contact me via email if you like to have the changed scope in advance and are able to sign stuff yourself.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Apache POI import class HSSFSheet error

Postby juan.cristobo » Mon Nov 23, 2015 7:54 pm

Oh, thanks!

I don't know how to sign, so I'll wait until the release.
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 9 guests