• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading excel file inside jar file using jxl api not working !!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can any body help me?

I am running mfc.jar file from path: D:\Nidhi\final\.

This jar file contains package mfcalculator and mfcreport.xls file. So
excel file is outside mfcalculator.
I am reading this xls file in mfcalculator\Report.java by following code:

Workbook template = Workbook.getWorkbook(new File("mfcreport.xls"));

This work fine if I run class file but gives I/O exception as mfcreport.xls inside jar can not be read .
If I put mfcreport.xls in the same directory where my jar file is,it detects excel file.

Is there any way to wrap excel file inside jar file?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You can obtain an InputStream representing a file within a jar file by using

getClass().getResourceAsStream(String)

The InputStream can then be passed to the

Workbook.getWorkbook(java.io.InputStream) method
 
Rakhee Atri ,78
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for giving prompt reply.
It worked perfectly.

Again,similiar sort of problem I am facing,when I have to execute "MAC.vbs"
file again in jar.
I have tried two ways:

Using URL to get File Object.

URL url = getClass().getResource("MAC.vbs");
URI uri = url.toURI();
File filename = new File(uri);

Using string "File name"

Relevant Code is :

String filenam = getClass().getResource("MAC.vbs").getFile().replaceAll("%20", " ") ;

File filename = new File(filenam);

Process p = Runtime.getRuntime().exec("WScript.exe " + filenam);
Process p1 = Runtime.getRuntime().exec("rundll32 SHELL32.DLL, ShellExec_RunDLL " + filename.getAbsolutePath());

But I am getting errors for both.

Can u pl. tell me the way out?
 
reply
    Bookmark Topic Watch Topic
  • New Topic